marty000123 Posted December 24, 2015 Share Posted December 24, 2015 Hi lads. I tried to create a script in where I have to make a command to give players a UZI skill. But now, when I type the command, everyone in the whole server gets the skill, but I am looking for the feature to give the skill to just one person. What do I exactly have to add to the script? I don't have a clue. I made the command to be admin-only. This is what I have got so far: function changePedStats(thePlayer, commandName) if setPlayerStat(thePlayer, 75, 1000) then outputChatBox("Congratulations! You have got dual wield UZI stats!") end end addCommandHandler("givestats", changePedStats, true) Any help would be appreciated. Regards, Marty Link to comment
AMARANT Posted December 24, 2015 Share Posted December 24, 2015 I can't see in your script setting the skill to 1000. I can see only the message to ALL players. Link to comment
Noki Posted December 25, 2015 Share Posted December 25, 2015 setPedStat/setPlayerStat (use setPedStat as setPlayerStat is deprecated) only work server-side. So make sure your script is set as server-sided in meta.xml. The first argument in a function with a command handler is the player who executed the command. If you want to specify the dual uzi skill for another player, you'll need to do something like this: function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end function changePedStats(thePlayer, _, name) local plr = getPlayerFromPartialName(name) if (not plr) then outputChatBox("There is no player with this name", thePlayer) return end local stat = setPedStat(plr, 75, 1000) if (stat) then outputChatBox("Congratulations! You have given "..getPlayerName(plr).." dual UZIs!", thePlayer) end end addCommandHandler("givestats", changePedStats, true) If you just want it to be for the player who typed the command, do something like this: function changePedStats(thePlayer, _) local stat = setPedStat(thePlayer, 75, 1000) if (stat) then outputChatBox("Congratulations! You have got dual wield UZI stats!", thePlayer) end end addCommandHandler("givestats", changePedStats, true) Link to comment
marty000123 Posted December 25, 2015 Author Share Posted December 25, 2015 Hi Noki, Thanks alot for your help! I tested it and it works completely fine. But how do I make it that the players who get's the skills get the message, and not me when I give the skill to the player? Link to comment
Noki Posted December 25, 2015 Share Posted December 25, 2015 outputChatBox("You have been given dual wield UZIs by "..getPlayerName(thePlayer), plr) That would only work in the case of the first code I gave. Link to comment
marty000123 Posted December 26, 2015 Author Share Posted December 26, 2015 The first code was the needed one indeed, thanks alot! But when you die/relog, you lose the skills. How do I make it so it saves? Link to comment
Noki Posted December 26, 2015 Share Posted December 26, 2015 setAccountData getAccountData Couple that with a few obvious events (onPlayerQuit, onPlayerWasted, onPlayerJoin etc) and that would be the simplest way to implement persistent skills. Link to comment
marty000123 Posted December 27, 2015 Author Share Posted December 27, 2015 (edited) Hi Noki. I am going to try and add the following script to my already existing script: function onPlayerQuit() local playerAccount = getPlayerAccount(source) -- get his account if (playerAccount) then -- if we got the account then local playerMoney = getPlayerMoney(source) -- get his money amount setAccountData(playerAccount, "piraterpg.money", playerMoney) -- store his current money amount in his account data end end addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) -- add an event handler function onPlayerLogin() -- when a player logins, retrieve his money amount from his account data and set it local playerAccount = getPlayerAccount(source) -- get his account if (playerAccount) then -- if we got the account then local playerMoney = getAccountData(playerAccount, "piraterpg.money") -- get the money amount was store in his account data -- make sure there was actually a value saved under this key (check if playerMoney is not false). -- this will for example not be the case when a player plays the gametype for the first time if (playerMoney) then setPlayerMoney(source, playerMoney) end end end addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) -- add an event handler I have found this script on the mta wiki, and will edit it that it will work on my server with the stats saver. I made this: function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end function changePedStats(thePlayer, _, name) local plr = getPlayerFromPartialName(name) if (not plr) then outputChatBox("There is no player with this name", thePlayer) return end local stat = setPedStat(plr, 75, 1000) if (stat) then outputChatBox("Congratulations! You have given "..getPlayerName(plr).." dual UZIs!", thePlayer) end end addCommandHandler("givestats", changePedStats, true) function onPlayerQuit() local playerAccount = getPlayerAccount(source) if (playerAccount) then local pedStats = getPedStat(source) setAccountData(playerAccount, "zi.pedstats", pedStats) end end addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) function onPlayerLogin() local playerAccount = getPlayerAccount(source) if (playerAccount) then local pedStats = getAccountData(playerAccount, "zi.pedstats") if (pedStats) then setPedStats(source, pedStats) end end end addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) Right now I'm actually a noob in scripting, so don't expect too much. I'm learning it. The script above, do you think this will work? Marty Edited December 27, 2015 by Guest Link to comment
Noki Posted December 27, 2015 Share Posted December 27, 2015 There's no such function as "getPedStats". Use getPedStat to get the uzi stat, then save that. But besides that it looks pretty good. Give it a go and let me know how it turns out. Link to comment
marty000123 Posted December 27, 2015 Author Share Posted December 27, 2015 Hi, It turns out that it doesn't work. When I die / relog and give myself an UZI through the admin panel, I just have one uzi. Any help would be appreciated. Marty Link to comment
Noki Posted December 27, 2015 Share Posted December 27, 2015 function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end function changePedStats(thePlayer, _, name) local plr = getPlayerFromPartialName(name) if (not plr) then outputChatBox("There is no player with this name", thePlayer) return end local stat = setPedStat(plr, 75, 1000) if (stat) then outputChatBox("Congratulations! You have given "..getPlayerName(plr).." dual UZIs!", thePlayer) end end addCommandHandler("givestats", changePedStats, true) function onPlayerQuit() local playerAccount = getPlayerAccount(source) if (playerAccount) then local pedStats = getPedStat(source, 75) setAccountData(playerAccount, "zi.pedstats", pedStats) end end addEventHandler("onPlayerQuit", root, onPlayerQuit) addEventHandler("onPlayerWasted", root, onPlayerQuit) function onPlayerLogin() local playerAccount = getPlayerAccount(source) if (playerAccount) then local pedStats = getAccountData(playerAccount, "zi.pedstats") if (pedStats) then setPedStat(source, 75, pedStats) end end end addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) Give this a go. 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