EngMohamedLish Posted June 8, 2015 Share Posted June 8, 2015 Here, In this script i have something wrong, i don't understand. This script is for reviving players, after their death, when i try to /revive [player name or even id] It returns to that "else" else outputChatBox ("There's no online player with this name.", source) However, the player's available..... What's wrong here? server: Reveal hidden contents addCommandHandler ("revive", function(user, cmd, user2) if isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( user ) ), aclGetGroup ( "Admin" ) ) then if cmd and user2 then local ID = tonumber(user2) if ID then local target = exports.ID_System:getPlayerFromID(ID) else local target = exports.ID_System:getPlayerFromPartialName(user2) end if target then if isPedDead(target) then local x, y, z = getElementPosition (target) spawnPlayer(target, x, y, z) else outputChatBox("This player is still alive", source) end else outputChatBox ("There's no online player with this name.", source) end else outputChatBox ("[syntax] /revive [iD/Partial Name]", source) end end end) Link to comment
TAPL Posted June 8, 2015 Share Posted June 8, 2015 Remove local from line 6 and 8. And change source to user. Link to comment
EngMohamedLish Posted June 8, 2015 Author Share Posted June 8, 2015 TAPL said: Remove local from line 6 and 8. And change source to user. Still nothing.. I believe, it won't do change, as 'source' is the handler of the command, and local will work, as the script's still in the same function, yup? Anyways, help please ! addCommandHandler ("revive", function(user, cmd, user2) if isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( user ) ), aclGetGroup ( "Admin" ) ) then if cmd and user2 then local ID = tonumber(user2) if ID then local target = exports.ID_System:getPlayerFromID(ID) else local target = exports.ID_System:getPlayerFromPartialName(user2) end if target then if isPedDead(target) then local x, y, z = getElementPosition (target) spawnPlayer(target, x, y, z) else outputChatBox("This player is still alive", user) end else outputChatBox ("There's no online player with this name.", user) end else outputChatBox ("[syntax] /revive [iD/Partial Name]", user) end end end) Link to comment
TAPL Posted June 8, 2015 Share Posted June 8, 2015 Nope, it restricted inside the if statement. Link to comment
EngMohamedLish Posted June 8, 2015 Author Share Posted June 8, 2015 TAPL said: Nope, it restricted inside the if statement. You are totally Right ! Thanks for your help, man. Link to comment
EngMohamedLish Posted June 8, 2015 Author Share Posted June 8, 2015 EngMohamedLish said: TAPL said: Nope, it restricted inside the if statement. You are totally Right ! Thanks for your help, man. But, here's something: target = exports.ID_System:getPlayerFromPartialName(user2) This part, doesn't work, as when i write a player name, it returns to the same 'else' which i showed, before. But, when i write a player ID, it works fine. Link to comment
TAPL Posted June 8, 2015 Share Posted June 8, 2015 I guess there might be something wrong with the function getPlayerFromPartialName. Link to comment
EngMohamedLish Posted June 8, 2015 Author Share Posted June 8, 2015 TAPL said: I guess there might be something wrong with the function getPlayerFromPartialName. Reveal hidden contents function getPlayerFromPartialName ( source, player_name, script ) if ( player_name ) then local sucess, value = getNameMatches ( player_name ) if ( sucess ) then local matches = ( type ( value ) == "table" ) and #value or 1 if ( matches == 1 ) then if ( script ) then return value else local player_nick = getPlayerName ( value ) local player_id = getElementData ( value, "ID" ) outputChatBox ( "(" .. player_id .. ") " .. player_nick, source, 255, 255, 0 ) end else outputChatBox ( "Players matching your search are: ", source, 255, 255, 0 ) for k, player in ipairs ( value ) do local player_nick = getPlayerName ( value[k] ) local player_id = getElementData ( value[k], "ID" ) outputChatBox ( "(" .. player_id .. ") " .. player_nick, source, 255, 255, 0 ) end return true, true end else if ( script ) then return false else outputChatBox ( "Players matching your search are: ", source, 255, 255, 0 ) outputChatBox ( value, source, 255, 0, 0 ) end end end end Here's the function. Link to comment
EngMohamedLish Posted June 8, 2015 Author Share Posted June 8, 2015 EngMohamedLish said: TAPL said: I guess there might be something wrong with the function getPlayerFromPartialName. Reveal hidden contents function getPlayerFromPartialName ( source, player_name, script ) if ( player_name ) then local sucess, value = getNameMatches ( player_name ) if ( sucess ) then local matches = ( type ( value ) == "table" ) and #value or 1 if ( matches == 1 ) then if ( script ) then return value else local player_nick = getPlayerName ( value ) local player_id = getElementData ( value, "ID" ) outputChatBox ( "(" .. player_id .. ") " .. player_nick, source, 255, 255, 0 ) end else outputChatBox ( "Players matching your search are: ", source, 255, 255, 0 ) for k, player in ipairs ( value ) do local player_nick = getPlayerName ( value[k] ) local player_id = getElementData ( value[k], "ID" ) outputChatBox ( "(" .. player_id .. ") " .. player_nick, source, 255, 255, 0 ) end return true, true end else if ( script ) then return false else outputChatBox ( "Players matching your search are: ", source, 255, 255, 0 ) outputChatBox ( value, source, 255, 0, 0 ) end end end end Here's the function. It is in the same script, which is ID_system, I think it may help? Reveal hidden contents function processIDCommands ( source, command, input ) if ( tonumber ( input ) ) then local player, playername = getPlayerFromID ( tonumber(input) ) if ( player ) then outputChatBox ( "Player that matches that id: ", source, 255, 255, 0 ) outputChatBox ( "(" .. input .. ") " .. playername, source, 255, 255, 0, true ) else outputChatBox ( playername, source, 255, 0, 0 ) -- in this case, playername carries the error. It's just to minimize the amount of code if an error is ecountered. end else local player = getPlayer ( source, input ) if ( player ) then outputChatBox ( "Player that matches that id: ", source, 255, 255, 0 ) outputChatBox ( "(" .. tostring ( getElementData ( player, "ID" ) ) .. ") " .. getPlayerName ( player ), source, 255, 255, 0, true ) end end end addCommandHandler ( "id", processIDCommands ) Link to comment
EngMohamedLish Posted June 8, 2015 Author Share Posted June 8, 2015 TAPL said: I guess there might be something wrong with the function getPlayerFromPartialName. Actually, fixed it, Thanks for your time, tapl 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