Georges1999 Posted December 11, 2017 Share Posted December 11, 2017 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
Georges1999 Posted December 11, 2017 Author Share Posted December 11, 2017 i meant functions and event but i couldn't modify my post. Link to comment
itHyperoX Posted December 11, 2017 Share Posted December 11, 2017 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
Georges1999 Posted December 12, 2017 Author Share Posted December 12, 2017 okay, thank you , i'll look into it. ~Georges Link to comment
Fist Posted December 12, 2017 Share Posted December 12, 2017 (edited) 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 December 12, 2017 by Fist 1 Link to comment
Georges1999 Posted December 12, 2017 Author Share Posted December 12, 2017 Yeah this looks way better. Cause i already had a script that creates peds. Thank you. ~Georges Link to comment
Moderators IIYAMA Posted December 12, 2017 Moderators Share Posted December 12, 2017 @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
Fist Posted December 12, 2017 Share Posted December 12, 2017 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 IIYAMA Posted December 12, 2017 Moderators Share Posted December 12, 2017 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now