AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_user_weapons question on 3rd param (https://forums.alliedmods.net/showthread.php?t=27009)

Geesu 04-13-2006 00:52

get_user_weapons question on 3rd param
 
So get_user_weapons has a 3rd param, at first I thought this was just so that we would know how many weapons the user has...

I'm curious as to why it adds this number to the initial array position?

Code:
static cell AMX_NATIVE_CALL get_user_weapons(AMX *amx, cell *params) /* 3 param */ {   int index = params[1];   if (index < 1 || index > gpGlobals->maxClients){     LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index);     return 0;   }   CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);   if (pPlayer->ingame){     cell *cpNum = get_amxaddr(amx,params[3]);     cell *cpIds = get_amxaddr(amx,params[2]);     *cpIds = 0;     int weapons = pPlayer->pEdict->v.weapons & ~(1<<31); // don't count last element     for(int i = 1; i < MAX_WEAPONS; ++i)     {       if (weapons & (1<<i))       {         *(cpIds+(*cpNum)) = i;         (*cpNum)++;       }     }     return weapons;   }   return 0; }

Notice the
Code:
*(cpIds+(*cpNum)) = i;

Why is it +cpNum? Just spent like 40 minutes debugging b/c I thought I f'ed something up then I noticed this...

Was just curious why this decision was made? I can't see the point :(

Josh

BAILOPAN 04-13-2006 00:53

Most likely this was done in the case of a mod with more than 32 weapons. That way you could keep requesting more or something.

Other than that, I have no idea. OLO is a strange one.


All times are GMT -4. The time now is 05:09.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.