Jump to content

Just one thing


Georges1999

Recommended Posts

Hello guys,i am new to scripting Lua and i need one thing. 

I am not asking you guys for a code. but just the keywords.

i want the thing that helps to make my idea come true in the server. My idea is that when the player kills a Ped the server rewards him the amount that i set for it.

I want to know the keywords that i need to use.

Thank you

~Georges 

Link to comment
createPedFun()
    local thePed = createPed(0, x,y,z)
    setElementData(thePed, "ped_ya", true)
end
addEventHandler -- on ResourceStart


function died(ammo, killer, killerWeapon, bodypart)
    if getElementData(source, "ped_ya") == true then
       givePlayerMoney(killer, 5000)
    end
end
addEventHandler("onPedWasted", root, died)

should work

Link to comment
18 hours ago, TheMOG said:

createPedFun()
    local thePed = createPed(0, x,y,z)
    setElementData(thePed, "ped_ya", true)
end
addEventHandler -- on ResourceStart


function died(ammo, killer, killerWeapon, bodypart)
    if getElementData(source, "ped_ya") == true then
       givePlayerMoney(killer, 5000)
    end
end
addEventHandler("onPedWasted", root, died)

should work

This will only work on specified peds, this ain't cool to do every ped hand by hand, only if you want them to be in particular area.

This one is way better, it will work for every ped that has been killed.

server side:

local reward;

addEventHandler("onPedWasted",root,function(_,killer)
	if (killer and getElementType(killer) == "player") then
		reward = math.random(1000,5000);
		givePlayerMoney(killer,reward)
	end
end);

 

Edited by Fist
  • Like 1
Link to comment
  • Moderators

@Fist Why do you declare the variable outside of the function? (Just wondering)

In lua there is no performance difference if you declare them inside or outside of a function.(unlike some other languages) You just want them as fast as possible out of your memory.

 

 

 

Link to comment
1 hour ago, IIYAMA said:

@Fist Why do you declare the variable outside of the function? (Just wondering)

In lua there is no performance difference if you declare them inside or outside of a function.(unlike some other languages) You just want them as fast as possible out of your memory.

 

 

 

i did it 'cause i recently read somewhere about garbage collection, didn't read it fully though. So each time ped is being killed it doesn't create a extra variable inside that event handler but instead uses already defined one. I don't know if that helps but it doesn't hurt giving it a try.

Link to comment
  • Moderators
7 minutes ago, Fist said:

i did it 'cause i recently read somewhere about garbage collection, didn't read it fully though. So each time ped is being killed it doesn't create a extra variable inside that event handler but instead uses already defined one. I don't know if that helps but it doesn't hurt giving it a try.

Ah, don't worry about the garbage collector. It is an automatic system that removes inaccessible objects and content when it's buffer is full.

Just script how you want! The readability is after al your performance! :)

 

 

 

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...