• 03 Mai 2025, 14:47:51


Auteur Sujet: Probleme /spawncar  (Lu 1463 fois)

0 Membres et 1 Invité sur ce sujet

Hors ligne [DaD]Kizo

  • *
  • Nouveau
  • Messages: 15
    • Voir le profil
Probleme /spawncar
« 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.

Hors ligne cristab

  • *
  • Messages: 8379
    • Voir le profil
Re : Probleme /spawncar
« Réponse #1 le: 29 Avril 2009, 21:02:09 »
cmd = strtok(cmdtext, idx); pour voir
pas d'aide en PM, vous êtes sur un forum est il me semble que vous êtes la pour avoir de l'aide donc pourquoi MP une seul personne qui ne vous répondra pas alors qu'il y a plein de membre ici

Hors ligne [DaD]Kizo

  • *
  • Nouveau
  • Messages: 15
    • Voir le profil
Re : Probleme /spawncar
« Réponse #2 le: 29 Avril 2009, 21:05:46 »
Nan ca marche pas =/

Hors ligne MrFredo

  • *
  • Grand Banditisme
  • Scripteur PHP/PAWN
  • Messages: 953
    • Voir le profil
    • GTA-Hosting
Re : Probleme /spawncar
« Réponse #3 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

Hors ligne [DaD]Kizo

  • *
  • Nouveau
  • Messages: 15
    • Voir le profil
Re : Probleme /spawncar
« Réponse #4 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.

Hors ligne MrFredo

  • *
  • Grand Banditisme
  • Scripteur PHP/PAWN
  • Messages: 953
    • Voir le profil
    • GTA-Hosting
Re : Probleme /spawncar
« Réponse #5 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)'

Hors ligne [DaD]Kizo

  • *
  • Nouveau
  • Messages: 15
    • Voir le profil
Re : Probleme /spawncar
« Réponse #6 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

Hors ligne MrFredo

  • *
  • Grand Banditisme
  • Scripteur PHP/PAWN
  • Messages: 953
    • Voir le profil
    • GTA-Hosting
Re : Probleme /spawncar
« Réponse #7 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

Hors ligne [DaD]Kizo

  • *
  • Nouveau
  • Messages: 15
    • Voir le profil
Re : Probleme /spawncar
« Réponse #8 le: 30 Avril 2009, 01:22:55 »
Waaaaaa ! Merci ! ça marche nikel !

Merci à toi :D