aymeness81 Posted August 1, 2013 Share Posted August 1, 2013 Hi , I have made this script, its a Bodyguard job. But I need help, I want it gives money only for players that are in Bodyguards team. Thanks for advance Server SIide: function createbTeam() bTeam = createTeam("Bodyguard", 255, 255, 255) uTeam = createTeam("Unemployed", 255, 255, 0) end addEventHandler ("onResourceStart", resourceRoot, createbTeam) function beginjob ( localPlayer ) setPlayerTeam ( source, bTeam ) setElementData (source, "Occupation", "Bodyguard", true) giveWeapon (source, 31, 5000) setElementModel ( source, 166 ) setPlayerNametagColor(source, 255, 255, 255) outputChatBox("You are now employed as Staff's Bodyguard. ", source, 255, 255, 0) outputChatBox("You Won't be able to walk , just fire to protect the base.. ", source, 255, 255, 0) outputChatBox("You can use Invincible Mode by typing /bodyguard when you are protecting the base.", source, 255, 255, 0) outputChatBox("To leave the job, just type /quitjob ", source, 0, 255, 0) setElementFrozen(source, true) triggerEvent("payday", source) end addEvent("bjob", true) addEventHandler("bjob",root,beginjob) function quitjob ( thePlayer ) setPlayerTeam ( source, uTeam ) setElementData (source, "Occupation", "Unemployed", true) setElementModel ( source, 78 ) outputChatBox("You are now Unemployed. ", source, 255, 255, 0) setElementFrozen(source, false) takeWeapon(source, 31, 5000) end addEvent("qjob", true) addEventHandler("qjob",root,quitjob) function gaga(thePlayer) if getElementData(thePlayer,"invincible") then setElementData(thePlayer,"invincible",false) outputChatBox("Invincible Mode is now off.",thePlayer,255,255,255) else setElementData(thePlayer,"invincible",true) outputChatBox("Invincible Mode is now on.",thePlayer,255,255,255) end end addCommandHandler("bodyguard",gaga) function payday() mon = math.random ( 10000, 25000 ) setTimer( givePlayerMoney, 1200000, 300, source, mon ) setTimer( outputChatBox, 1200000, 300, "Here is your payement.You can continue protecting to earn more. You got $ "..mon, source, 255, 255, 0 ) end addEvent("payday", true) addEventHandler("payday",root,payday) Client Side: GUIEditor = { staticimage = {}, label = {}, button = {}, window = {}, memo = {} } bjobwindow = guiCreateWindow(310, 186, 493, 314, "Job: Bodyguard", false) guiWindowSetSizable(bjobwindow, false) guiSetVisible(bjobwindow, false) GUIEditor.memo[1] = guiCreateMemo(28, 25, 283, 159, "This is a Bodyguard Job, you need just to Protect this Staff's base.\nYou won't be able to walk.\nYou'll get your reward every 20 minutes.\nBe sure to don't let criminals attack it.\n\n#Job Created By Staffs Members.\n#Thanks for protecting us.", false, bjobwindow) GUIEditor.staticimage[1] = guiCreateStaticImage(375, 53, 108, 110, ":bodyguard/Login.png", false, bjobwindow) abjob = guiCreateButton(77, 253, 128, 38, "Accept", false, bjobwindow) dbjob = guiCreateButton(321, 253, 128, 38, "Decline", false, bjobwindow) GUIEditor.label[1] = guiCreateLabel(234, 201, 175, 42, "CRP:RPG", false, bjobwindow) local font_0 = guiCreateFont(":bodyguard/font.ttf") guiSetFont(GUIEditor.label[1], font_0) guiLabelSetColor(GUIEditor.label[1], 6, 35, 210) bMarker = createMarker ( 2865.9826660156, -1948.5070800781, 10.109375, "cylinder", 1.5 ) function Bjob(hitElement) if getElementType(hitElement) == "player" and (hitElement == localPlayer) then if not guiGetVisible(bjobwindow) then guiSetVisible(bjobwindow, true) showCursor(true) end end end addEventHandler("onClientMarkerHit", bMarker, Bjob) function Bjobleave(leaveElement) if getElementType(leaveElement) == "player" and (leaveElement == localPlayer) then if guiGetVisible(bjobwindow) then guiSetVisible(bjobwindow, false) showCursor(false) end end end addEventHandler("onClientMarkerLeave", bMarker, Bjobleave) function joinTeam() triggerServerEvent("bjob",localPlayer) guiSetVisible(bjobwindow, false) showCursor(false) end addEventHandler("onClientGUIClick", abjob , joinTeam, false) function removeBWindow() guiSetVisible(bjobwindow, false) showCursor(false) end addEventHandler("onClientGUIClick", dbjob , removeBWindow, false) function quitbjob() triggerServerEvent("qjob", localPlayer) end addCommandHandler("quitjob", quitbjob) Link to comment
Baseplate Posted August 1, 2013 Share Posted August 1, 2013 loop through all the players in the bodyguard team then give them the money. getPlayersInTeam givePlayerMoney Link to comment
aymeness81 Posted August 1, 2013 Author Share Posted August 1, 2013 I tried this but dont works.. function createbTeam() bTeam = createTeam("Bodyguard", 255, 255, 255) end addEventHandler ("onResourceStart", resourceRoot, createbTeam) function payday() local playersb = getPlayersInTeam(bTeam) mon = math.random ( 10000, 25000 ) setTimer( givePlayerMoney, 1200000, 300, playersb, mon ) setTimer( outputChatBox, 1200000, 300, "Here is your payement.You can continue protecting to earn more. You got $ "..mon, playersb, 255, 255, 0 ) end Link to comment
Baseplate Posted August 1, 2013 Share Posted August 1, 2013 function createbTeam() bTeam = createTeam("Bodyguard", 255, 255, 255) end addEventHandler ("onResourceStart", resourceRoot, createbTeam) function payday() local players = getPlayersInTeam (bTeam) for _, v in ipairs ( players ) do mon = math.random ( 10000, 25000 ) givePlayerMoney(players, money) outputChatBox("Here is your payement.You can continue protecting to earn more. You got $ "..mon, players, 255, 255, 0) end end setTimer(payday, 1200000, 0) Link to comment
iMr.3a[Z]eF Posted August 1, 2013 Share Posted August 1, 2013 (edited) How long you want to give, i mean every 5 hours or? function createbTeam() bTeam = createTeam("Bodyguard", 255, 255, 255) end addEventHandler ("onResourceStart", resourceRoot, createbTeam) setTimer( function payday() local playersb = getPlayersInTeam(bTeam) money = math.random ( 10000, 25000 ) givePlayerMoney(playersb, money) end, 1200000, 0) Edited August 1, 2013 by Guest Link to comment
Moderators IIYAMA Posted August 1, 2013 Moderators Share Posted August 1, 2013 setTimer( givePlayerMoney, 1200000, 300, playersb, mon ) 1200000 / 1000 = 1200 sec 1200 / 60 = 20 minutes timer This is amount is correct? local bodyGuardTimers = {} bodyGuardTimers[playersb] = setTimer(function () if isElement(playersb) then givePlayerMoney( playersb, mon ) outputChatBox("Here is your payement.You can continue protecting to earn more. You got $ "..mon, playersb, 255, 255, 0 ) else local timer = bodyGuardTimers[playersb] if isTimer ( timer ) then killTimer ( timer ) end bodyGuardTimers[playersb] = nil end end,1200000, 300) Link to comment
iMr.3a[Z]eF Posted August 1, 2013 Share Posted August 1, 2013 setTimer( givePlayerMoney, 1200000, 300, playersb, mon ) 1200000 / 1000 = 1200 sec 1200 / 60 = 20 minutes timer This is amount is correct? local bodyGuardTimers = {} bodyGuardTimers[playersb] = setTimer(function () if isElement(playersb) then givePlayerMoney( playersb, mon ) outputChatBox("Here is your payement.You can continue protecting to earn more. You got $ "..mon, playersb, 255, 255, 0 ) else local timer = bodyGuardTimers[playersb] if isTimer ( timer ) then killTimer ( timer ) end bodyGuardTimers[playersb] = nil end end,1200000, 300) What is this code?, Also what is "mon" in your code? Link to comment
Moderators IIYAMA Posted August 1, 2013 Moderators Share Posted August 1, 2013 Something that have to fit in the other code..... I don't define mon cause it is in his own function, so if that is within his function block there is no reason to define it in my code. It will remain local with the timer till the timer stops. Link to comment
iMr.3a[Z]eF Posted August 1, 2013 Share Posted August 1, 2013 So, try mine i hope it'll works. function createbTeam() bTeam = createTeam("Bodyguard", 255, 255, 255) end addEventHandler ("onResourceStart", resourceRoot, createbTeam) setTimer( function payday() local playersb = getPlayersInTeam(bTeam) money = math.random ( 10000, 25000 ) givePlayerMoney(playersb, money) end, 1200000, 0) Link to comment
Moderators IIYAMA Posted August 1, 2013 Moderators Share Posted August 1, 2013 So, try mine i hope it'll works. function createbTeam() bTeam = createTeam("Bodyguard", 255, 255, 255) end addEventHandler ("onResourceStart", resourceRoot, createbTeam) setTimer( function payday() local playersb = getPlayersInTeam(bTeam) money = math.random ( 10000, 25000 ) givePlayerMoney(playersb, money) end, 1200000, 0) You created an infinity, that never got killed.Players are going to be rich forever even if he started another job.After the player leaves, the playersb don't exist and your server got filled up with erros.etc. Tables can safe you, functions can destroy you. I will recommend you to start working with tables, cause the reason why role-play gamemodes are laggy is because the infinity timers and they are to lazy to use a table system. Tables are very quick, where a function takes 1000 ms of time to find info, a table can do that in 1 ms.The only difference is that functions are using uptodate information and tables only the last stored data. Ram is something great, use it well. Link to comment
aymeness81 Posted August 1, 2013 Author Share Posted August 1, 2013 No one of those codes work.. Thanks anyway Link to comment
Moderators IIYAMA Posted August 2, 2013 Moderators Share Posted August 2, 2013 Some can work with tables and some (aymeness81) people can't, 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