• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Lua Script] Effect on Death and on Kill (solved)

StormRusher

New Member
Joined
Dec 23, 2009
Messages
138
Reaction score
0
Well i want a script that do an effect on corpse when a player dies, and an effect in a player who have fraged, like "DOWN!" and "FRAG!"

thanks
 
Last edited:
Code:
function onKill(cid, target)
local config = {
rand = math.random(1,4),
pos = getPlayerPosition(target)
}
        local table = {
        {"Smashed!", 189, 1},
        {"Dead!", 190, 2},
        {"Owned!", 18, 3},
        {"Pwnt!", 215, 4}
}
        if(isPlayer(target) == TRUE) then  
          local rand = math.random(1, #table)
           doSendAnimatedText(config.pos, table[rand][1], table[rand][2])
               doSendMagicEffect(getCreaturePosition(target), math.random(1, 32)) 
              end 
                return TRUE    
                   end
 
Very minor fixes o_O
Code:
local t = {
	{"Smashed!", 189},
	{"Dead!", 190},
	{"Owned!", 18},
	{"Pwnt!", 215}
}
function onKill(cid, target)
	if(isPlayer(target) == TRUE) then
		local rand = math.random(#t)
		doSendAnimatedText(getThingPos(cid), t[rand][1], t[rand][2])
		doSendMagicEffect(getThingPos(target), math.random(32))
	end 
	return TRUE    
end
 
edit~~

forget to register on login.lua

worked well :)
(only a little changes, with the math.random: "math.random(32))" to "math.random(1,32))")

rep+
 
Last edited:
edit~~

forget to register on login.lua

worked well :)
(only a little changes, with the math.random: "math.random(32))" to "math.random(1,32))")

rep+

math.random
math.random() generates pseudo-random numbers uniformly distributed. Supplying argument alters its behaviour:

* math.random() with no arguments generates a real number between 0 and 1.
* math.random(upper) generates integer numbers between 1 and upper.
* math.random(lower, upper) generates integer numbers between lower and upper.

> = math.random()
0.0012512588885159
> = math.random()
0.56358531449324
> = math.random(100)
20
> = math.random(100)
81
> = math.random(70,80)
76
> = math.random(70,80)
75

^ u don't have to change to math.random(1,32)
 
oh you're right man, i dont knew that
thanks, another doubt, have a function to return the current player/creture position?

because getPlayerPosition(cid) isnt working, i'm using tfs 0.3.5

i found getCreatureLastPosition(cid), but i dont want the last position :X
 
Try using this:
LUA:
local playerPos = getThingPos(cid)


Also, an example with basic Lua (how to print out a table's contents):
LUA:
local position = { x = 1000, y = 1500, z = 7}
for index, value in pairs(position) do
print(index .." => " .. value)
end
Output:
Code:
y => 1500
x => 1000
z => 7
 
thanks for the example, now i understand better the "for"

i dont know whats wrong Cykotitan:

LUA:
function onKill(cid, target)
	local playerPos = getThingPos(cid)
	if(isPlayer(target) == TRUE) then
		doSendAnimatedText(getThingPos(target), config.down[randomchance], config.downcolor[randomchance])
		doSendAnimatedText(playerPos, config.frag[randomchance], config.fragcolor[randomchance])
		doSendMagicEffect(getThingPos(target), 65)
	end 
	return TRUE    
end

it send the animatedtext and the effect in the target, but dont send the text in the killer (cid), i tried with getPlayerPos, getPlayerPosition, getCreaturePosition, no one worked :X

then i tested with getCreatureLastPosition and worked... i think these functions which didnt work, dont work in tfs 0.3.5 o.O

someone have an idea? another way to send the text in the current player position? :confused:
 
Last edited:
LUA:
function onKill(cid, target, lastHit)

local text =
{
	{"Smashed!", 189},
	{"Dead!", 190},
	{"Owned!", 18},
	{"Pwnt!", 215}
}

	if not isPlayer(target) then
		return true
	end

	local random = math.random(table.maxn(text))
	doSendAnimatedText(getCreaturePosition(cid), "Frag!", 25)
	doSendAnimatedText(getCreaturePosition(target), text[random][1], text[random][2])
	return true
end

This should work..
 
Last edited:
Back
Top