RO
pedido

Usando O Random No Script. Pedido.

Por rod_doidim, 14 de jul. de 2012 em Scripts

script
11
1.3k
rod_doidimR
14 de julho de 2012 às 16:28

O Script abaixo tem a função de premiar um jogador com dinheiro quando ele mata outro jogador.

 

Eu queria adicionar prêmios aleatórios.

 

 

 

config = {

reward = 500 -- Defina o quanto o jogador ganhará...

}

function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)

if(isPlayer(lastHitKiller) == TRUE) then

doPlayerAddMoney(lastHitKiller, config.reward)

doPlayerSendTextMessage(lastHitKiller, MESSAGE_STATUS_CONSOLE_ORANGE, "Voc\ê matou " .. getCreatureName(cid) .. " e recebeu " .. config.reward .. " GPs.")

end

return TRUE

end

 

** Se puder ser por OnKill, é mais fácil ?

Grato.

Editado Julho 15 por rod_doidim

OneshotO
14 de julho de 2012 às 16:38

local config = {
rewards = {
	{"money", 500},
	{2157, 10}
}
}

function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
if isPlayer(lastHitKiller) then
	local reward = config.rewards[math.random(1, #config.rewards)]
	if type(reward[1]) == "number" then
		local item = doCreateItemEx(reward[1], reward[2])
		if not item then
			return true
		end
		return doPlayerAddItemEx(lastHitKiller, item)
	end
	doPlayerAddMoney(lastHitKiller, reward[2])
	doPlayerSendTextMessage(lastHitKiller, MESSAGE_STATUS_CONSOLE_ORANGE, "Você matou ".. getCreatureName(cid) .." e recebeu ".. (reward[1] == "money" and (reward[2] .." GPs") or (reward[2] .." ".. getItemNameById(reward[1]))) ..".")
end
return true
end

 

Você pode configurar recompensas em dinheiro ou itens. Deixei por padrão uma recompensa de 500 gps ou 10 gold nuggets.

 

Abraços.

Editado Julho 14 por Oneshot

rod_doidimR
15 de julho de 2012 às 12:34

Não funcionou :/

Editado Julho 15 por rod_doidim

LeoxtibiaL
15 de julho de 2012 às 12:48
local reward = {2160, 2148, 7590}   --- id dos itens

function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
if(isPlayer(lastHitKiller) == TRUE) then
local randomChance = math.random(1, #reward)
doPlayerAddItem(cid, reward[randomChance],1)
doPlayerSendTextMessage(lastHitKiller, MESSAGE_STATUS_CONSOLE_ORANGE, "Voc\ê matou " .. getCreatureName(cid) .. " e recebeu " .. config.reward .. " GPs.")
end
return TRUE
end

rod_doidimR
15 de julho de 2012 às 13:37

Nada brother :/

Fiz o teste. Coloquei um char pra matar o outro e não recebeu.

 

O evento está no login.lua

E está como type="death". no creaturescript.lua

LeoxtibiaL
15 de julho de 2012 às 13:44

Não prestei atenção no script, pra mim ele já funcionava. Tente fazer assim então::

 

local reward = {2160, 2148, 7590}   --- id dos itens

function onKill(cid, target, lastHit)
if isPlayer(cid) and isPlayer(target) then
local randomChance = math.random(1, #reward)
doPlayerAddItem(cid, reward[randomChance], 1)
end
return TRUE
end

 

Em creaturescripts/scripts/login.lua coloque antes do return true: registerCreatureEvent(cid, "killplayer")

Em creturescripts.xml cole a tag: <event type="kill" name="killplayer" event="script" value="NOMEDOSEUARQUIVO.lua"/>

rod_doidimR
15 de julho de 2012 às 14:02

Usei desta forma,

 

local reward = {5878, 5902, 5890, 2480, 5876, 5947, 5948, 5891, 5887, 5889, 5888, 5875, 5880, 5892, 5893, 5924, 5885, 5887, 2182, 2186, 2185, 8911, 2181, 2183, 2190, 2191, 2188, 8921, 2189, 2187, 2392, 5809, 2193, 5903, 2160}

 

function onKill(cid, target, lastHit)

if isPlayer(cid) and isPlayer(target) then

local randomChance = math.random(1, #reward)

doPlayerAddItem(cid, reward[randomChance], 1)

end

return TRUE

end

 

E não funcionou ... hehe

LeoxtibiaL
15 de julho de 2012 às 14:09

Deu algum erro? Alguns servidores não tem a função onKill, tenta por onDeath então:

 

local reward = {5878, 5902, 5890, 2480, 5876, 5947, 5948, 5891, 5887, 5889, 5888, 5875, 5880, 5892, 5893, 5924, 5885, 5887, 2182, 2186, 2185, 8911, 2181, 2183, 2190, 2191, 2188, 8921, 2189, 2187, 2392, 5809, 2193, 5903, 2160}

function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
if isPlayer(cid) and isPlayer(target) then
local randomChance = math.random(1, #reward)
doPlayerAddItem(cid, reward[randomChance], 1)
end
return TRUE
end

 

Troca lá na tag: type="kill" por type="death"

rod_doidimR
15 de julho de 2012 às 14:27

É 0.3.6 +

15 de julho de 2012 às 14:50

local reward = {5878, 5902, 5890, 2480, 5876, 5947, 5948, 5891, 5887, 5889, 5888, 5875, 5880, 5892, 5893, 5924, 5885, 5887, 2182, 2186, 2185, 8911, 2181, 2183, 2190, 2191, 2188, 8921, 2189, 2187, 2392, 5809, 2193, 5903, 2160}

function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)

if isPlayer(lastHitKiller) and isPlayer(cid) then
doPlayerAddItem(lastHitKiller, reward[math.random(#reward)])
end

return true
end

 

tenta isso.

 

edit: usa a tag do death

Editado Julho 15 por Demonbholder

rod_doidimR
15 de julho de 2012 às 15:17

Coloquei tudo do jeito que me falou.

Registrei no login.lua

Registrei no creaturescript como Death.

 

E não ganha nada.

 

 

 

15:16 Warning! The murder of Testes was not justified.

Sem recompensa.