Predator Posted February 10, 2012 Posted February 10, 2012 So, here's my problem: I wan't to make a script so a player spawns with guns depending on witch ACL group he's in. I have made this script, but it doesn't work.. function giveWeaponsOnSpawn ( theSpawnpoint, theTeam ) local account = getPlayerAccount(thePlayer) if (not account or isGuestAccount(account)) then return end local accountName = getAccountName(account) if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( "Admin" ) ) ) then giveWeapon ( source, 1, 9999 ) giveWeapon ( source, 4, 9999 ) giveWeapon ( source, 24, 9999 ) giveWeapon ( source, 27, 9999 ) giveWeapon ( source, 32, 9999 ) giveWeapon ( source, 31, 9999 ) giveWeapon ( source, 34, 9999 ) giveWeapon ( source, 36, 9999 ) giveWeapon ( source, 39, 9999 ) giveWeapon ( source, 40, 9999 ) giveWeapon ( source, 44, 9999 ) giveWeapon ( source, 46, 9999 ) end end addEventHandler ( "onPlayerSpawn", getRootElement(), giveWeaponsOnSpawn ) When I remove all that ACL group thing the script works just fine, but when i try to add the ACL thing, I get an error: WARNING: spawnweps\DW.lua:2: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nil] If anyone could help me with that I would really appreciate it
Castillo Posted February 10, 2012 Posted February 10, 2012 Your only problem is that you used "thePlayer" instead of "source" in getPlayerAccount, but I changed some things to make your script easier to use. local weapons = { ["Admin"] = {[1] = 9999, [4] = 9999, [24] = 9999, [27] = 9999, [32] = 9999, [31] = 9999, [34] = 9999, [36] = 9999, [39] = 9999, [40] = 9999, [44] = 9999, [46] = 9999}, } function giveWeaponsOnSpawn ( theSpawnpoint, theTeam ) local account = getPlayerAccount(source) if (not account or isGuestAccount(account)) then return end local accountName = getAccountName(account) if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( "Admin" ) ) ) then for weapon, ammo in pairs(weapons["Admin"]) do giveWeapon(source, weapon, ammo, true) end end end addEventHandler ( "onPlayerSpawn", getRootElement(), giveWeaponsOnSpawn )
Predator Posted February 11, 2012 Author Posted February 11, 2012 Ty a lot! It works! I want to ask something other too.. I tryied to do the same for stats but it kinda failed, could you fix it ? local stats = { ["DanWesson"] = {[69] = 1000, [70] = 1000, [71] = 1000, [72] = 1000, [73] = 1000, [74] = 1000, [75] = 1000, [76] = 1000, [77] = 1000, [78] = 1000, [79] = 1000, [160] = 1000}, } function changePedStat ( theSpawnpoint, theTeam ) local account = getPlayerAccount(source) if (not account or isGuestAccount(account)) then return end local accountName = getAccountName(account) if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( "DanWesson" ) ) ) then for stat, value in pairs(stat["DanWesson"]) do setPedstat(source, stat, value, true) end end end addEventHandler ( "onPlayerSpawn", getRootElement(), setPedStat )
Castillo Posted February 11, 2012 Posted February 11, 2012 You put: "setPedstat", Lua is case sensitive, see your error? it has to be: "setPedStat". Also your table name is "stats", but then you're using "stat". local stats = { ["DanWesson"] = {[69] = 1000, [70] = 1000, [71] = 1000, [72] = 1000, [73] = 1000, [74] = 1000, [75] = 1000, [76] = 1000, [77] = 1000, [78] = 1000, [79] = 1000, [160] = 1000}, } function changePedStat ( theSpawnpoint, theTeam ) local account = getPlayerAccount(source) if (not account or isGuestAccount(account)) then return end local accountName = getAccountName(account) if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( "DanWesson" ) ) ) then for stat, value in pairs(stats["DanWesson"]) do setPedStat(source, stat, value, true) end end end addEventHandler ( "onPlayerSpawn", getRootElement(), changePedStat ) Also you call your function "changePedStat" but then you add the event handler to "setPedStat". NEVER CALL A FUNCTION LIKE A MTA NATIVE FUNCTION.
Predator Posted February 11, 2012 Author Posted February 11, 2012 Hmm, I see my fault, thank you for the advise, and for the help with the script.
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