h4x7o0r Posted December 18, 2011 Share Posted December 18, 2011 Hi guys, I have a "push" script that works just for the player who use it .I wanna change it somehow that only admins be able to push online players. Then i wanna integrate it into a GUI (maybe when i press "N" for example, the panel will be shown) that i can select a player from a list of active players and then to have a "PUSH" button . Here is the my script : function push () player=getLocalPlayer() -- I think i need to modify something if isPedInVehicle(player) then local vehicle=getPedOccupiedVehicle(player) x,y,z=getElementVelocity(vehicle) setElementVelocity ( vehicle, x, y, z+0.25) end end addCommandHandler ( "push", push, true) I know that i need to find the "target" player and also i need this : function findPlayer(name) if not name then return false end local name = name:lower() for i, p in ipairs(getElementsByType("player")) do local fullname = getPlayerName(p):lower() if string.find(fullname:gsub("#%x%x%x%x%x%x", ""), name, 1, true) then return p end end return false end How can i put all togheter ? Link to comment
GTX Posted December 18, 2011 Share Posted December 18, 2011 function push (thePlayer, commandName, namepart) player = findPlayer(namepart) if not player then outputChatBox("* /push: player not found", thePlayer) elseif isPedInVehicle(player) then local vehicle = getPedOccupiedVehicle(player) x,y,z = getElementVelocity(vehicle) setElementVelocity ( vehicle, x, y, z + 0.25 ) end end addCommandHandler("push", push) Try this Link to comment
Al3grab Posted December 18, 2011 Share Posted December 18, 2011 SetElementVelocity wont work alone , i suggest to use getElementSpeed+setElementSpeed from Useful functions : https://wiki.multitheftauto.com/wiki/SetElementSpeed https://wiki.multitheftauto.com/wiki/GetElementSpeed function push (thePlayer, commandName, namepart) if hasObjectPermissionTo ( thePlayer, "function.banPlayer",false ) then -- check if he has permissions player = findPlayer(namepart) if not player then outputChatBox("* /push: player not found", thePlayer) return end if isPedInVehicle(player) then local vehicle = getPedOccupiedVehicle(player) local push = 60 setElementSpeed ( vehicle,"mph", getElementSpeed(vehicle, "mph") + push ) end end end addCommandHandler("push", push) function setElementSpeed(element, unit, speed) -- only work if element is moving! if (unit == nil) then unit = 0 end if (speed == nil) then speed = 0 end speed = tonumber(speed) local acSpeed = getElementSpeed(element, unit) if (acSpeed~=false) then -- if true - element is valid, no need to check again local diff = speed/acSpeed local x,y,z = getElementVelocity(element) setElementVelocity(element,x*diff,y*diff,z*diff) return true end return false end function getElementSpeed(element,unit) if (unit == nil) then unit = 0 end if (isElement(element)) then local x,y,z = getElementVelocity(element) if (unit=="mph" or unit==1 or unit =='1') then return (x^2 + y^2 + z^2) ^ 0.5 * 100 else return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 end else outputDebugString("Not an element. Can't get speed") return false end end function findPlayer(name) if not name then return false end local name = name:lower() for i, p in ipairs(getElementsByType("player")) do local fullname = getPlayerName(p):lower() if string.find(fullname:gsub("#%x%x%x%x%x%x", ""), name, 1, true) then return p end end return false end Link to comment
Castillo Posted December 18, 2011 Share Posted December 18, 2011 (edited) @Al3grab: Do you even know what are you saying? because it makes no sense . function push (thePlayer, commandName, namepart) local player = findPlayer(namepart) if (not player) then outputChatBox("* /push: player not found", thePlayer) else local vehicle = getPedOccupiedVehicle(player) if (not vehicle) then outputChatBox("* /push: This player is not in a vehicle", thePlayer) return end local x,y,z = getElementVelocity(vehicle) setElementVelocity ( vehicle, x, y, z + 0.25 ) end end addCommandHandler("push", push) function findPlayer(name) if not name then return false end local name = name:lower() for i, p in ipairs(getElementsByType("player")) do local fullname = getPlayerName(p):lower() if string.find(fullname:gsub("#%x%x%x%x%x%x", ""), name, 1, true) then return p end end return false end Edited December 18, 2011 by Guest Link to comment
h4x7o0r Posted December 18, 2011 Author Share Posted December 18, 2011 Thank you very much guys, but it looks like's not working. GTX - I don't have any error just a public message "/push: player not found" so the player wasn't found. Al3grab - error line 3 - attempt to call global "hasObjectPermissionTo" (a nil value) I appreciate your help. LE: thank you solidsnake14 - (same like gtx) no errors but it says "/push: player not found" . Link to comment
Castillo Posted December 18, 2011 Share Posted December 18, 2011 (edited) function push (thePlayer, commandName, namepart) local player = findPlayer(namepart) if (not player) then outputChatBox("* /push: player not found", thePlayer) else local vehicle = getPedOccupiedVehicle(player) if (not vehicle) then outputChatBox("* /push: This player is not in a vehicle", thePlayer) return end local x,y,z = getElementVelocity(vehicle) setElementVelocity ( vehicle, x, y, z + 0.25 ) end end addCommandHandler("push", push) function findPlayer(playerPart) local pl = getPlayerFromName(playerPart) if isElement(pl) then return pl else for i,v in ipairs (getElementsByType ("player")) do if (string.find(getPlayerName(v),playerPart)) then return v end end end end Edited December 18, 2011 by Guest Link to comment
h4x7o0r Posted December 18, 2011 Author Share Posted December 18, 2011 Warning - Bad argument @ 'getPlayerFromName' expected script at argument 1, got nil Error - Bad argument #2 to 'find' (string expected, got nil) Link to comment
Castillo Posted December 18, 2011 Share Posted December 18, 2011 Are you writing the command like this: /push <the player name who to push> Link to comment
h4x7o0r Posted December 18, 2011 Author Share Posted December 18, 2011 For sure. for example for [XYZ]ABC42 i use : /push abc . Link to comment
Castillo Posted December 18, 2011 Share Posted December 18, 2011 Copy my last code again, I found the bug. Link to comment
h4x7o0r Posted December 18, 2011 Author Share Posted December 18, 2011 sorry but no change , same errors Link to comment
Castillo Posted December 18, 2011 Share Posted December 18, 2011 I tested the script, it works fine. Link to comment
h4x7o0r Posted December 18, 2011 Author Share Posted December 18, 2011 Thank you for your help. For the moment was my bad that i've had set "client" not "server-side" now it's working, no errors, but "/push: player not found" Link to comment
Castillo Posted December 18, 2011 Share Posted December 18, 2011 it means that the player does not exists. Link to comment
h4x7o0r Posted December 18, 2011 Author Share Posted December 18, 2011 Thank you very mych, yeah, not i checked with full name and i see that it needs to be the same, can't use only a part of the name. Link to comment
Castillo Posted December 18, 2011 Share Posted December 18, 2011 The part of name works perfectly fine, I'd /push Cast and my name was (SAUR)Castillo and it worked. Maybe it doesn't work if your name is like "ABC" and you do "abc", the lower case. Link to comment
h4x7o0r Posted December 18, 2011 Author Share Posted December 18, 2011 Thank you very much SolidSnake14 for all your help. I've modified the findPlayer function and not it works as i want . Here's is the final code : function push (thePlayer, commandName, namepart) local player = findPlayer(namepart) if (not player) then outputChatBox("* /push: player not found", thePlayer) else local vehicle = getPedOccupiedVehicle(player) if (not vehicle) then outputChatBox("* /push: This player is not in a vehicle", thePlayer) return end local x,y,z = getElementVelocity(vehicle) setElementVelocity ( vehicle, x, y, z + 0.25 ) end end addCommandHandler("push", push) function findPlayer(thePlayer) if not thePlayer then return false end local thePlayer = thePlayer:lower() for i, p in ipairs(getElementsByType("player")) do local fullname = getPlayerName(p):lower() if string.find(fullname:gsub("#%x%x%x%x%x%x", ""), thePlayer, 1, true) then return p end end return false end And now maybe another hard part i don't have any ideea how can i make that GUI ? Link to comment
HunT Posted December 19, 2011 Share Posted December 19, 2011 Download my old version race admin panel with 16 functions Here : https://community.multitheftauto.com/index.php?p= ... ls&id=2877 Link to comment
h4x7o0r Posted December 19, 2011 Author Share Posted December 19, 2011 Thank you for reply, i have had ur resource but as i remember it's encrypted and can't inspect the code to see how it works. Link to comment
HunT Posted December 19, 2011 Share Posted December 19, 2011 Thank you for reply, i have had ur resource but as i remember it's encrypted and can't inspect the code to see how it works. Start the GUI project and i help u with PM Link to comment
h4x7o0r Posted December 19, 2011 Author Share Posted December 19, 2011 Thank you for your help but i'm 0 knowledge in gui, i've tried guieditor resource, but for the moment haven't got the point how it works 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