[SOLVED] GivePlayerWeapon not working -
quagga - 09.11.2012
I don't usually request scripting help but this has really confused me. GivePlayerWeapon doesn't seam to be working. I have a weapons array with ammo and data (common in a lot of scripts) to save weapons for players. The data is loading into the array fine from the database and everything seems to be working, however GivePlayerWeapon is refusing to function. I have added a printf() to help debug the problem and it looks like everything is working fine.
PHP код:
for(new i=0; i<13; i++) {
if(weapons[i][1] > 0) {
GivePlayerWeapon(playerid, weapons[i][1], weapons[i][2]);
printf("Slot %i: Weapon=%i, Ammo=%i", i, weapons[i][1], weapons[i][2]);
}
}
When I log into the server and that code runs I am supposed to be supplied with a deagle with 14 rounds. Here is the printf from the above code:
Код:
[17:25:13] Slot 2: Weapon=24, Ammo=14
So as you can see the weapons[] array is working perfectly and the loop is functioning properly since the slot number is 0, but I don't get my deagle when I log in.
Any help would be greatly appreciated... My community's entire development team has looked at this and none can figure it out. We all agree it looks perfect and it should be working.
Respuesta: GivePlayerWeapon not working -
Marricio - 09.11.2012
Try using SetSpawnInfo before you spawn the player, just to discard options.
Re: GivePlayerWeapon not working -
quagga - 09.11.2012
I do use SetSpawnInfo and SpawnPlayer but that happens before this code is triggered. I just use 0's for all of the weapons in SetSpawnInfo because this code should give the weapons afterwards.
Respuesta: GivePlayerWeapon not working -
Marricio - 09.11.2012
Well, try doing this, just before you spawn the player.
pawn Код:
for(new i=0; i<13; i++) {
if(weapons[i][1] > 0) {
SetSpawnInfo( playerid, team, skin, x, y, z, angle, weapons[i][1], weapons[i][2], 0, 0, 0, 0 );
printf("Slot %i: Weapon=%i, Ammo=%i", i, weapons[i][1], weapons[i][2]);
}
}
Re: GivePlayerWeapon not working - Emmet_ - 09.11.2012
1) Is it under OnPlayerSpawn?
2) What is playerid? Show us a bit more code.
Re: GivePlayerWeapon not working -
[KHK]Khalid - 09.11.2012
Hmm, looks fine to me as well. Try debugging
playerid, you might be giving a weapon to someone else (or even a player that isn't connected).
Re: GivePlayerWeapon not working -
Abreezy - 09.11.2012
Quote:
Originally Posted by Emmet_
1) Is it under OnPlayerSpawn?
2) What is playerid? Show us a bit more code.
|
Playerid is a number assigned per player connected to a server, each number is unique, for example if you connected first on the server, you would get a unique number, such as 0, next player would be 1, then 2, then 3.
Now being on point, the playerid is being grabbed from the login. Obviously there was no issue with it, as he never stated he was getting undefined playerid, or such.
Using a mini timer after loading the data should fix all issues, since it would allow time for it to be loaded and then process it with GivePlayerWeapon. Hope this fixes it, good luck!
Re: GivePlayerWeapon not working -
quagga - 09.11.2012
SOLVED
For future reference for everyone else I simply set a 1 second timer on it. And to answer the question of where this code was it was in the dialog response for the login password dialog.
Thank you everyone who tried helping.