19.01.2014, 05:40
Hello,
I have played with scripting a gamemode in pawn before, but I am new to using this plugin by xeeZ.
So far I have got a working game mode but with some issues, here are the relevant functions:
here is an image with some output:

I realize I should be checking for if it's a valid player or not, but I think there is some deeper issue I don't understand here.
If I put in "/fix 1", and there is nobody with ID 1, I would expect the output from this code to say
But if you notice when I type anything other than /fix (a valid id), the messages seem to get mangled
I am guessing it has something to do with fscm being in a different thread and data getting overwritten, but I don't really understand it.
If somebody can give me an idea what's going on here that would be awesome.
Thanks.
P.S: I know this is the plugin development section, but I think this is more relevant to plugin development than scripting. Let me know if I'm wrong.
I have played with scripting a gamemode in pawn before, but I am new to using this plugin by xeeZ.
So far I have got a working game mode but with some issues, here are the relevant functions:
Код:
void fscm(int nPlayerID, const char * Format, ...)
{
char szBuffer[1024];
va_list args;
va_start(args, Format);
vsprintf(szBuffer, Format, args);
if (SendClientMessage(nPlayerID, 0xFFFFFFFF, szBuffer))
{
}
va_end(args);
}
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerCommandText(int playerid, const char *cmdtext)
{
fscm(playerid, "cmdtext: %s", cmdtext);
char *token1 = NULL;
char seps[] = " ";
token1 = strtok((char*)cmdtext, seps);
char szPlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME);
if (strcmp(token1, "/fix") == 0)
{
int nTargetID = 0;
int nResult = sscanf(cmdtext + strlen(token1) + 1, "%d", &nTargetID);
if (nResult == 1)
{
}
else
nTargetID = playerid;
fscm(playerid, "res: %d | tid: %d | pid: %d", nResult, nTargetID, playerid);
int nCurVehicle = GetPlayerVehicleID(nTargetID);
char szTargetName[MAX_PLAYER_NAME];
GetPlayerName(nTargetID, szTargetName, MAX_PLAYER_NAME);
if (nCurVehicle)
{
SetVehicleHealth(nCurVehicle, 1000.0f);
RepairVehicle(nCurVehicle);
fscm(playerid, "You have fixed a vehicle for %s (%d).", szTargetName, nTargetID);
}
else
{
fscm(playerid, "%s (%d) is not in a vehicle.", szTargetName, nTargetID);
}
return true;
}
}

I realize I should be checking for if it's a valid player or not, but I think there is some deeper issue I don't understand here.
If I put in "/fix 1", and there is nobody with ID 1, I would expect the output from this code to say
Quote:
|
res: 1 | tid: 1 | pid: 0 (1) is not in a vehicle. |
Quote:
|
res: 1 | tid: 1 | pid: 0 res: 1 | tid: 1 | pid: (1) is not in a vehicle. |
If somebody can give me an idea what's going on here that would be awesome.
Thanks.
P.S: I know this is the plugin development section, but I think this is more relevant to plugin development than scripting. Let me know if I'm wrong.


