GTAOnline.net

San Andreas Multiplayer (sa:mp) => Scripting SA-MP [Pawn center] => Discussion démarrée par: [DaD]Kizo le 29 Avril 2009, 20:37:50

Titre: Probleme /spawncar
Posté par: [DaD]Kizo le 29 Avril 2009, 20:37:50
Salut voila j'ai un autre petit problème, j'ai une commande /spawncar mais il y a une ligne que je n'arrive pas à régler =/

new cmd[256];
new strtok;
new idx;

if (strcmp(cmd, "/spawncar", true, 9)==0)
{
      cmd = strtok(cmdtext, idx)
if(!strlen(cmd))
{
        SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /spawncar [car number]");
return 1;
         }
    new param2=strval(cmd);
    if(param2>611)
    {
        SendClientMessage(playerid, 0xFFFFFFAA, "carnumber must be between 400 and 611");
return 1;
     }
if(param2<400)
        {
        SendClientMessage(playerid, 0xFFFFFFAA, "carnumber must be between 400 and 611");
return 1;
}
    new Float:x;
    new Float:y;
    new Float:z;
    new Float:p;
    new rand1 = random(126);
    new rand2 = random(126);

    GetPlayerFacingAngle(playerid, p);
    GetPlayerPos(playerid, x, y, z);
      CreateVehicle(param2,x+3.0*floatsin(-p,degrees),y+3.0*floatcos(-p,degrees),z+0.5, p+90.0, rand1, rand2, 600);
    return 1;
}

La ligne qui marche pas: cmd = strtok(cmdtext, idx)

les erreurs:

D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(665) : error 012: invalid function call, not a valid address
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(665) : warning 215: expression has no effect
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(665) : warning 215: expression has no effect
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(665) : error 001: expected token: ";", but found ")"
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(665) : error 029: invalid expression, assumed zero
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(665) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
Titre: Re : Probleme /spawncar
Posté par: cristab le 29 Avril 2009, 21:02:09
cmd = strtok(cmdtext, idx); pour voir
Titre: Re : Probleme /spawncar
Posté par: [DaD]Kizo le 29 Avril 2009, 21:05:46
Nan ca marche pas =/
Titre: Re : Probleme /spawncar
Posté par: MrFredo le 29 Avril 2009, 21:11:10
new cmd[256],tmp[256],idx;
cmd = strtok(cmdtext, idx);
if (strcmp(cmd, "/spawncar", true)==0)
{
      tmp= strtok(cmdtext, idx);
if(!strlen(tmp))
{
        SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /spawncar [car number]");
return 1;
         }
new param2=strval(tmp);
if(param2 < 400 || param2 > 611)
{
        SendClientMessage(playerid, 0xFFFFFFAA, "carnumber must be between 400 and 611");
return 1;
}
         new Float:x, Float:y,Float:z,Float:p;
         new rand1 = random(126);
         new rand2 = random(126);

GetPlayerFacingAngle(playerid, p);
GetPlayerPos(playerid, x, y, z);
      CreateVehicle(param2,x+3.0*floatsin(-p,degrees),y+3.0*floatcos(-p,degrees),z+0.5, p+90.0, rand1, rand2, 600);
return 1;
}


Donc j'ai fait quelque modif enfet 'cmd = strtok(cmdtext,idx);' devait allait en haut de la callback OnPlayerCommandText ensuite tu recupere le parametre avec un nouveau strtok (tmp = strtok(cmdtext,idx)) j'ai aussi modifier t'est condition sur param2 et 2 ou 3 petite chose pour racourcir le code, compare le a ton ancien pour bien comprendre t'est erreur
Titre: Re : Probleme /spawncar
Posté par: [DaD]Kizo le 29 Avril 2009, 23:59:05
Merci pour ta réponse MrFredo, j'ai essayé comme toi mais il me reste des erreurs, toujours sur la même ligne  ;D

new cmd[256],tmp[256], strtok, idx;

cmd = strtok(cmdtext, idx)
if (strcmp(cmd, "/spawncar", true)==0)
{
      tmp = strtok(cmdtext,idx);
if(!strlen(tmp))
{
        SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /spawncar [car number]");
return 1;
         }
new param2=strval(tmp);
if(param2 < 400 || param2 > 611)
{
        SendClientMessage(playerid, 0xFFFFFFAA, "carnumber must be between 400 and 611");
return 1;
}
  new Float:x, Float:y,Float:z,Float:p;
    new rand1 = random(126);
      new rand2 = random(126);
     
GetPlayerFacingAngle(playerid, p);
GetPlayerPos(playerid, x, y, z);
CreateVehicle(param2,x+3.0*floatsin(-p,degrees),y+3.0*floatcos(-p,degrees),z+0.5, p+90.0, rand1, rand2, 600);
return 1;
}

D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(715) : error 012: invalid function call, not a valid address
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(715) : warning 215: expression has no effect
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(715) : warning 215: expression has no effect
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(715) : error 001: expected token: ";", but found ")"
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(715) : error 029: invalid expression, assumed zero
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(715) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
Titre: Re : Probleme /spawncar
Posté par: MrFredo le 30 Avril 2009, 00:18:13
Regarde bien mon code tu met une variable nomé  'strtok' alor que c'est une fonction, tu oublie encore une fois le ';' a la fin de 'cmd = strtok(cmdtext,idx)'
Titre: Re : Probleme /spawncar
Posté par: [DaD]Kizo le 30 Avril 2009, 00:49:12
Ok mais je comprend pas, ça marche toujours pas :'( ,

new cmd[256],tmp[256],idx;
cmd = strtok(cmdtext, idx);
if (strcmp(cmd, "/spawncar", true)==0)
{
tmp= strtok(cmdtext, idx);
if(!strlen(tmp))
{
  SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /spawncar [car number]");
return 1;
  }
new param2=strval(tmp);
if(param2 < 400 || param2 > 611)
{
  SendClientMessage(playerid, 0xFFFFFFAA, "carnumber must be between 400 and 611");
return 1;
}
  new Float:x, Float:y,Float:z,Float:p;
  new rand1 = random(126);
    new rand2 = random(126);

GetPlayerFacingAngle(playerid, p);
GetPlayerPos(playerid, x, y, z);
  CreateVehicle(param2,x+3.0*floatsin(-p,degrees),y+3.0*floatcos(-p,degrees),z+0.5, p+90.0, rand1, rand2, 600);
return 1;
}

D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(399) : error 017: undefined symbol "strtok"
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(399) : error 033: array must be indexed (variable "cmd")
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(402) : error 017: undefined symbol "strtok"
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(402) : error 033: array must be indexed (variable "tmp")
D:\GTA San Andreas\GTA San Andreas\gamemodes\DaDtest.pwn(398) : warning 203: symbol is never used: "idx"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.

Pourtant c'est bien comme tu ma dis de faire
Titre: Re : Probleme /spawncar
Posté par: MrFredo le 30 Avril 2009, 01:03:06
Il te manque la fonction strtok


Voila je l'ai trouver en vitesse sur le wiki de sa-mp
Code: (pawn) [Sélectionner]
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
 
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}

Ajoute sa en bas de ton script j'pense que sa devrait marcher
Titre: Re : Probleme /spawncar
Posté par: [DaD]Kizo le 30 Avril 2009, 01:22:55
Waaaaaa ! Merci ! ça marche nikel !

Merci à toi :D