JeViCo Posted June 8, 2018 Share Posted June 8, 2018 (edited) Hello everyone! I think i'm missing something but i can't find it client-side: setTimer(function() veh = getPedOccupiedVehicle(localPlayer) if veh then paymultiplier = 2 speed = tonumber(getElementSpeed(veh,"km/h")) --if speed < 0 then speed = -speed end triggerServerEvent("payMoney",localPlayer,(paymultiplier*speed)) --givePlayerMoney(paymultiplier*speed) end end,1000,0) server-side: function pay(val) givePlayerMoney(source,val) end addEvent("payMoney",true) addEventHandler("payMoney",getRootElement(),pay) Nothing happens server-side. I checked the source: only i see a message with outputChatBox and val is a random number - everything perfect, but still i don't get money. What i'm doing wrong? Edited June 8, 2018 by Juuve Link to comment
JeViCo Posted June 8, 2018 Author Share Posted June 8, 2018 (edited) 3 minutes ago, Dimos7 said: What are you try to make? pay money but synced for each player( job script ) Edited June 8, 2018 by Juuve Link to comment
Dimos7 Posted June 8, 2018 Share Posted June 8, 2018 Maybe because speed it floor and not inter Link to comment
Fierelier Posted June 8, 2018 Share Posted June 8, 2018 (edited) veh = getPedOccipiedVehicle(localPlayer) Ya misspelled something: it's getPedOccupiedVehicle. Make sure you use /debugscript 3 when testing your scripts. It often helps you find mistakes like this. Also use client instead of source in the server-side code, as the sent player can be manipulated. You should also calculate the val on the server side, not client side. The client can just manipulate the number to be whatever. Never trust the client. Ever. With all the proposed changes I gave you, you can also make the script fully server-side. This is untested, but should work (server-side): local payMultiplier = 2 function payPlayers() for _,player in ipairs(getElementsByType("player")) do local veh = getPedOccupiedVehicle(player) if veh then givePlayerMoney(player,tonumber(getElementSpeed(veh,"km/h")*payMultiplier)) end end setTimer(payPlayers,1000,0) I put payMultiplier one level up, you don't need to re-define it every time the function is called. If it doesn't work, let me know. EDIT: Consider using math.round instead of tonumber! Edited June 8, 2018 by Fierelier 1 Link to comment
JeViCo Posted June 8, 2018 Author Share Posted June 8, 2018 12 minutes ago, Fierelier said: Never trust the client. Ever. Praise the server! It helped me out a lot. Thank you :3 1 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