rublisk19 Posted January 1, 2012 Share Posted January 1, 2012 (edited) I need help to make script that gives money to player for driving.Like job system!!!! it need to check if player are [example: policeman skin before giving money for delay time!! like :::: function enterVehicle ( theVehicle, seat, jacked) if ( policeVehicles[getElementModel ( theVehicle )] ) and (policeSkins[getElementModel ( source )] ) then >>Wait for 1min<<<< setElementData(player, "MONEY",tonumber(getElementData(player, "MONEY"))+180) elseif ( policeVehicles[getElementModel ( theVehicle )] ) and (not policeSkins[getElementModel ( source )] ) then removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Tu ne gaisrininkas!", source ) -- end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) -- Okey Thanks for help!!! Waiting replies Edited January 3, 2012 by Guest Link to comment
Castillo Posted January 1, 2012 Share Posted January 1, 2012 (edited) function enterVehicle ( theVehicle, seat, jacked) if ( policeVehicles[getElementModel ( theVehicle )] ) and (policeSkins[getElementModel ( source )] ) then setTimer(setElementData,5000,1,source, "MONEY",tonumber(getElementData(source, "MONEY"))+180) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Tu ne gaisrininkas!", source ) -- end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) -- Not sure if it'll work. Edited January 1, 2012 by Guest Link to comment
rublisk19 Posted January 1, 2012 Author Share Posted January 1, 2012 Error : Bad argument @ 'getElementData' [Expected element at argument 1, got nil] attempt to perform arithmetic on nil value Link to comment
Castillo Posted January 1, 2012 Share Posted January 1, 2012 Copy it again, I fixed a error. Link to comment
rublisk19 Posted January 1, 2012 Author Share Posted January 1, 2012 Copy it again, I fixed a error. Thanks works ;] Link to comment
rublisk19 Posted January 1, 2012 Author Share Posted January 1, 2012 You're welcome . Just a little problem it gives me money just 1 time i set setTimer(setElementData,6000,10, << to 10 but it just gives me 1 time no error anything and other little problem then i sit to car text pop up outputChatBox ( "Jus gavote alga 180Lt!", source ) - but i didn't drived 1min i know function start on player enter car is there any way to make text pop up after 1min ? Link to comment
Castillo Posted January 1, 2012 Share Posted January 1, 2012 That's because I set it to only run the timer once. And also I set it to 5 seconds, not 1 minute. function enterVehicle ( theVehicle, seat, jacked) if ( policeVehicles[getElementModel ( theVehicle )] ) and (policeSkins[getElementModel ( source )] ) then setTimer(payThePlayer,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Tu ne gaisrininkas!", source ) -- end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) -- function payThePlayer(thePlayer) if (not thePlayer) then return end setElementData(thePlayer,"MONEY",tonumber(getElementData(thePlayer, "MONEY"))+180) outputChatBox ( "Jus gavote alga 180Lt!", thePlayer ) end Link to comment
rublisk19 Posted January 1, 2012 Author Share Posted January 1, 2012 Script Hey then i reconnect i get in server error but everything works fine Link to comment
Castillo Posted January 1, 2012 Share Posted January 1, 2012 Try this: local timers = {} function enterVehicle ( theVehicle, seat, jacked) if ( policeVehicles[getElementModel ( theVehicle )] ) and (policeSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Tu ne gaisrininkas!", source ) -- end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) addEventHandler("onPlayerQuit",root, function () if isTimer(timers[source]) then killTimer(timers[source]) end end) function payThePlayer(thePlayer) if (not thePlayer) then if isTimer(timers[thePlayer]) then killTimer(timers[thePlayer]) end return end setElementData(thePlayer,"MONEY",tonumber(getElementData(thePlayer, "MONEY"))+180) outputChatBox ( "Jus gavote alga 180Lt!", thePlayer ) end Link to comment
rublisk19 Posted January 1, 2012 Author Share Posted January 1, 2012 Try this: local timers = {} function enterVehicle ( theVehicle, seat, jacked) if ( policeVehicles[getElementModel ( theVehicle )] ) and (policeSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Tu ne gaisrininkas!", source ) -- end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) addEventHandler("onPlayerQuit",root, function () if isTimer(timers[source]) then killTimer(timers[source]) end end) function payThePlayer(thePlayer) if (not thePlayer) then if isTimer(timers[thePlayer]) then killTimer(timers[thePlayer]) end return end setElementData(thePlayer,"MONEY",tonumber(getElementData(thePlayer, "MONEY"))+180) outputChatBox ( "Jus gavote alga 180Lt!", thePlayer ) end Thanks problem solved Edit: function enterVehicle ( theVehicle, seat, jacked) if ( policeVehicles[getElementModel ( theVehicle )] ) and (policeSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Jus ne policininkas!", source ) -- end elseif ( FireCars[getElementModel ( theVehicle )] ) and (FireSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer1,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Just ne gaisrininkas!", source ) -- end elseif ( medicCars[getElementModel ( theVehicle )] ) and (medicSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer2,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Just ne medikas!", source ) -- end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) i maked this but i get error end expected to close function at line 11 near elseif Link to comment
Castillo Posted January 1, 2012 Share Posted January 1, 2012 Try this: function enterVehicle ( theVehicle, seat, jacked) if ( policeVehicles[getElementModel ( theVehicle )] ) and (policeSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Jus ne policininkas!", source ) -- end if ( FireCars[getElementModel ( theVehicle )] ) and (FireSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer1,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Just ne gaisrininkas!", source ) -- end if ( medicCars[getElementModel ( theVehicle )] ) and (medicSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer2,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Just ne medikas!", source ) -- end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) Link to comment
rublisk19 Posted January 1, 2012 Author Share Posted January 1, 2012 Try this: function enterVehicle ( theVehicle, seat, jacked) if ( policeVehicles[getElementModel ( theVehicle )] ) and (policeSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Jus ne policininkas!", source ) -- end if ( FireCars[getElementModel ( theVehicle )] ) and (FireSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer1,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Just ne gaisrininkas!", source ) -- end if ( medicCars[getElementModel ( theVehicle )] ) and (medicSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer2,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox ( "Just ne medikas!", source ) -- end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) not work kicks me from car P.S. elseif doesn't kicked me from car but i get error Link to comment
Castillo Posted January 1, 2012 Share Posted January 1, 2012 Try this: function enterVehicle ( theVehicle, seat, jacked) if ( policeVehicles[getElementModel ( theVehicle )] ) and (policeSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer,60000,0,source) elseif ( FireCars[getElementModel ( theVehicle )] ) and (FireSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer1,60000,0,source) elseif ( medicCars[getElementModel ( theVehicle )] ) and (medicSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer2,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox("You're not allowed to use this vehicle", source) end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) Link to comment
rublisk19 Posted January 2, 2012 Author Share Posted January 2, 2012 Try this: function enterVehicle ( theVehicle, seat, jacked) if ( policeVehicles[getElementModel ( theVehicle )] ) and (policeSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer,60000,0,source) elseif ( FireCars[getElementModel ( theVehicle )] ) and (FireSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer1,60000,0,source) elseif ( medicCars[getElementModel ( theVehicle )] ) and (medicSkins[getElementModel ( source )] ) then timers[source] = setTimer(payThePlayer2,60000,0,source) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox("You're not allowed to use this vehicle", source) end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) Not work error attempt to index global 'timers' a nil value P.S. in game i get pay for anything i don't need to be in car Link to comment
BinSlayer1 Posted January 2, 2012 Share Posted January 2, 2012 the problem is that when the timer is finished and the 'player gets paid', there is no check that he is actually in a vehicle, while he could have gotten in one, then the setTimer would be triggered within 60 secs, but the player could have also gotten out of the vehicle while nothing stops him from doing so Link to comment
rublisk19 Posted January 2, 2012 Author Share Posted January 2, 2012 so how to make that ? Link to comment
Kenix Posted January 2, 2012 Share Posted January 2, 2012 Full code server: local timers = { } local policeSkins = { [280] = true, [281] = true, [282] = true, [283] = true, [284] = true, [285] = true, [286] = true } local FireSkins = { [277] = true, [278] = true, [279] = true } local medicSkins = { [274] = true, [275] = true, [276] = true } local policeVehicles = { [598] = true, [596] = true, [597] = true, [599] = true } local FireCars = { [407] = true, [544] = true } local medicCars = { [416] = true } function enterVehicle ( theVehicle, seat, jacked ) if ( policeVehicles[ getElementModel ( theVehicle ) ] ) and ( policeSkins[ getElementModel ( source ) ] ) then timers[source] = setTimer( payThePlayer,60000,0,source ) elseif ( FireCars[ getElementModel ( theVehicle ) ] ) and ( FireSkins[ getElementModel ( source ) ] ) then timers[source] = setTimer( payThePlayer1,60000,0,source ) elseif ( medicCars [getElementModel ( theVehicle ) ] ) and ( medicSkins[ getElementModel ( source ) ] ) then timers[source] = setTimer( payThePlayer2,60000,0,source ) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox("You're not allowed to use this vehicle", source) end end addEventHandler ( "onPlayerVehicleEnter", root, enterVehicle ) addEventHandler("onPlayerQuit",root, function( ) if isTimer( timers[source] ) then killTimer( timers[source] ) end timers[source] = nil end ) function payThePlayer( thePlayer ) if not thePlayer then if isTimer( timers[thePlayer] ) then killTimer( timers[thePlayer] ) end return end setElementData( thePlayer,"MONEY",tonumber( getElementData(thePlayer, "MONEY" ) )+180 ) outputChatBox ( "Jus gavote alga 180Lt!", thePlayer ) end function payThePlayer1( thePlayer ) if not thePlayer then if isTimer( timers[thePlayer] ) then killTimer( timers[thePlayer] ) end return end setElementData( thePlayer,"MONEY",tonumber( getElementData( thePlayer, "MONEY" ) )+380 ) outputChatBox ( "Jus gavote alga 380Lt!", thePlayer ) end function payThePlayer2( thePlayer ) if not thePlayer then if isTimer( timers[thePlayer] ) then killTimer( timers[thePlayer] ) end return end setElementData( thePlayer,"MONEY",tonumber( getElementData( thePlayer, "MONEY" ) )+580 ) outputChatBox ( "Jus gavote alga 580Lt!", thePlayer ) end Link to comment
rublisk19 Posted January 2, 2012 Author Share Posted January 2, 2012 NOT WORKS I GET MONEY THEN I EXIT CAR AND I CAN"T ENTER OTHER CARS JUST MY JOB Link to comment
Castillo Posted January 2, 2012 Share Posted January 2, 2012 Try this: local timers = { } local policeSkins = { [280] = true, [281] = true, [282] = true, [283] = true, [284] = true, [285] = true, [286] = true } local FireSkins = { [277] = true, [278] = true, [279] = true } local medicSkins = { [274] = true, [275] = true, [276] = true } local policeVehicles = { [598] = true, [596] = true, [597] = true, [599] = true } local FireCars = { [407] = true, [544] = true } local medicCars = { [416] = true } function enterVehicle ( theVehicle, seat, jacked ) if ( not policeVehicles[ getElementModel ( theVehicle ) ] and not FireCars[ getElementModel ( theVehicle ) ] and not medicCars[ getElementModel ( theVehicle ) ] ) then return end if ( policeVehicles[ getElementModel ( theVehicle ) ] ) and ( policeSkins[ getElementModel ( source ) ] ) then timers[source] = setTimer( payThePlayer,60000,0,source ) elseif ( FireCars[ getElementModel ( theVehicle ) ] ) and ( FireSkins[ getElementModel ( source ) ] ) then timers[source] = setTimer( payThePlayer1,60000,0,source ) elseif ( medicCars [getElementModel ( theVehicle ) ] ) and ( medicSkins[ getElementModel ( source ) ] ) then timers[source] = setTimer( payThePlayer2,60000,0,source ) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox("You're not allowed to use this vehicle", source) end end addEventHandler ( "onPlayerVehicleEnter", root, enterVehicle ) addEventHandler("onPlayerQuit",root, function( ) if isTimer( timers[source] ) then killTimer( timers[source] ) end timers[source] = nil end ) function exitVehicle() if isTimer( timers[source] ) then killTimer( timers[source] ) end timers[source] = nil end addEventHandler ( "onPlayerVehicleExit", root, exitVehicle ) function payThePlayer( thePlayer ) if not thePlayer then if isTimer( timers[thePlayer] ) then killTimer( timers[thePlayer] ) end return end setElementData( thePlayer,"MONEY",tonumber( getElementData(thePlayer, "MONEY" ) )+180 ) outputChatBox ( "Jus gavote alga 180Lt!", thePlayer ) end function payThePlayer1( thePlayer ) if not thePlayer then if isTimer( timers[thePlayer] ) then killTimer( timers[thePlayer] ) end return end setElementData( thePlayer,"MONEY",tonumber( getElementData( thePlayer, "MONEY" ) )+380 ) outputChatBox ( "Jus gavote alga 380Lt!", thePlayer ) end function payThePlayer2( thePlayer ) if not thePlayer then if isTimer( timers[thePlayer] ) then killTimer( timers[thePlayer] ) end return end setElementData( thePlayer,"MONEY",tonumber( getElementData( thePlayer, "MONEY" ) )+580 ) outputChatBox ( "Jus gavote alga 580Lt!", thePlayer ) end Link to comment
Kenix Posted January 2, 2012 Share Posted January 2, 2012 (edited) Try and write what output. local timers = { } local policeSkins = { [280] = true, [281] = true, [282] = true, [283] = true, [284] = true, [285] = true, [286] = true } local FireSkins = { [277] = true, [278] = true, [279] = true } local medicSkins = { [274] = true, [275] = true, [276] = true } local policeVehicles = { [598] = true, [596] = true, [597] = true, [599] = true } local FireCars = { [407] = true, [544] = true } local medicCars = { [416] = true } function enterVehicle ( theVehicle, seat, jacked ) if ( not policeVehicles[ getElementModel ( theVehicle ) ] and not FireCars[ getElementModel ( theVehicle ) ] and not medicCars[ getElementModel ( theVehicle ) ] ) then removePedFromVehicle ( source ) return end if ( policeVehicles[ getElementModel ( theVehicle ) ] ) and ( policeSkins[ getElementModel ( source ) ] ) then timers[source] = setTimer( payThePlayer,60000,0,source ) elseif ( FireCars[ getElementModel ( theVehicle ) ] ) and ( FireSkins[ getElementModel ( source ) ] ) then timers[source] = setTimer( payThePlayer1,60000,0,source ) elseif ( medicCars [getElementModel ( theVehicle ) ] ) and ( medicSkins[ getElementModel ( source ) ] ) then timers[source] = setTimer( payThePlayer2,60000,0,source ) else removePedFromVehicle ( source ) -- force the player out of the vehicle outputChatBox("You're not allowed to use this vehicle", source) end end addEventHandler ( "onPlayerVehicleEnter", root, enterVehicle ) addEventHandler("onPlayerQuit",root, function( ) if isTimer( timers[source] ) then killTimer( timers[source] ) end timers[source] = nil end ) function exitVehicle() if isTimer( timers[source] ) then killTimer( timers[source] ) end timers[source] = nil end addEventHandler ( "onPlayerVehicleExit", root, exitVehicle ) function payThePlayer( thePlayer ) if not isElement( thePlayer ) then if isTimer( timers[thePlayer] ) then killTimer( timers[thePlayer] ) end return end setElementData( thePlayer,"MONEY",tonumber( getElementData(thePlayer, "MONEY" ) )+180 ) outputChatBox ( "Jus gavote alga 180Lt!", thePlayer ) end function payThePlayer1( thePlayer ) if not isElement( thePlayer ) then if isTimer( timers[thePlayer] ) then killTimer( timers[thePlayer] ) end return end setElementData( thePlayer,"MONEY",tonumber( getElementData( thePlayer, "MONEY" ) )+380 ) outputChatBox ( "Jus gavote alga 380Lt!", thePlayer ) end function payThePlayer2( thePlayer ) if not isElement( thePlayer ) then if isTimer( timers[thePlayer] ) then killTimer( timers[thePlayer] ) end return end setElementData( thePlayer,"MONEY",tonumber( getElementData( thePlayer, "MONEY" ) )+580 ) outputChatBox ( "Jus gavote alga 580Lt!", thePlayer ) end p.s idk why it not work for you.. Edited January 2, 2012 by Guest Link to comment
Castillo Posted January 2, 2012 Share Posted January 2, 2012 Kenix: So far my script works perfect, I'm able to enter another vehicles other than Police and so on. Link to comment
Castillo Posted January 2, 2012 Share Posted January 2, 2012 I actually tested it before post. Link to comment
Kenix Posted January 2, 2012 Share Posted January 2, 2012 I tested it too and have same effect. 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