GivePlayerWeapon not working
#1

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=0i<13i++) {
            if(
weapons[i][1] > 0) {
            
GivePlayerWeapon(playeridweapons[i][1], weapons[i][2]);
            
printf("Slot %i: Weapon=%i, Ammo=%i"iweapons[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.
Reply
#2

Try using SetSpawnInfo before you spawn the player, just to discard options.
Reply
#3

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.
Reply
#4

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]);
            }

        }
Reply
#5

1) Is it under OnPlayerSpawn?
2) What is playerid? Show us a bit more code.
Reply
#6

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).
Reply
#7

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!
Reply
#8

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)