GTAOnline.net

San Andreas Multiplayer (sa:mp) => Scripting SA-MP [Pawn center] => Discussion démarrée par: Ashley11 le 11 Décembre 2012, 23:19:06

Titre: Commande spawn
Posté par: Ashley11 le 11 Décembre 2012, 23:19:06
Bonsoir, je bosse sur mon RP pour pouvoir ouvrir un serveur dessus, et j'ai un problème au niveau d'une commande.

Elle doit faire spawn un véhicule, mais quand je rentre le dernier parametre "proprio" je reçoit le return en pleine tronche  :closedeyes

pourtant "proprio" vaut bien la valeur que j'ai rentré, c'est plutot bizarre !


if(strcmp(cmd, "/spawnveh", true) == 0)
{
if(IsPlayerConnected(playerid))
{
    if(!(PlayerInfo[playerid][pAdmin] > 1338)) return SendClientMessage(playerid, COLOR_RED, "Vous n'êtes pas administrateur!");
new modelid, color1, color2, proprio;
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /spawnveh [model] [couleur1] [couleur2] [proprio]");
return 1;
}
        modelid = strval(tmp);
if(modelid < 400 || modelid > 560) { SendClientMessage(playerid, COLOR_GREY, "Type dé véhicule invalide!"); return 1; }
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /spawnveh [model] [couleur1] [couleur2] [proprio]");
return 1;
}
        color1 = strval(tmp);
if(color1 < 0 || color1 > 520) { SendClientMessage(playerid, COLOR_GREY, "Type de couleur invalide!"); return 1; }
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /spawnveh [model] [couleur1] [couleur2] [proprio]");
return 1;
}
        color2 = strval(tmp);
if(color2 < 0 || color2 > 520) { SendClientMessage(playerid, COLOR_GREY, "Type de couleur invalide!"); return 1; }
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /spawnveh [model] [couleur1] [couleur2] [proprio]");
return 1;
}
proprio = strval(tmp);
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /spawnveh [model] [couleur1] [couleur2] [proprio]");
return 1;
}

if(IsPlayerConnected(playerid))
{
new Float:X, Float:Y, Float:Z, Float:angle;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, angle);
X += floatmul(floatsin(-angle, degrees), 4.0);
Y += floatmul(floatcos(-angle, degrees), 4.0);
for(new i=1; i < MAX_DVEHICLES; i++)
{
if(!VehicleCreated[i])
{
new msg[128];
VehicleCreated[i] = 0;
VehicleModel[i] = modelid;
VehiclePos[i][0] = X;
VehiclePos[i][1] = Y;
VehiclePos[i][2] = Z;
VehiclePos[i][3] = angle+90.0;
VehicleColor[i][0] = color1;
VehicleColor[i][1] = color2;
VehicleInterior[i] = GetPlayerInterior(playerid);
VehicleWorld[i] = GetPlayerVirtualWorld(playerid);
VehicleValue[i] = 0;
valstr(VehicleOwner[i], proprio);
VehicleNumberPlate[i] = DEFAULT_NUMBER_PLATE;
for(new d=0; d < sizeof(VehicleTrunk[]); d++)
{
VehicleTrunk[i][d][0] = 0;
VehicleTrunk[i][d][1] = 0;
}
for(new d=0; d < sizeof(VehicleMods[]); d++)
{
VehicleMods[i][d] = 0;
}
VehiclePaintjob[i] = 255;
UpdateVehicleSpawned(i, 0);
SaveVehicle(i);
format(msg, sizeof(msg), "Véhicule ajouté [id %d]", i);
SendClientMessage(playerid, COLOR_WHITE, msg);
return 1;
}
}
}
SendClientMessage(playerid, COLOR_RED, "Erreur, nombre maximum de véhicules atteint!");
}
return 1;
}

Merci d'avance.
Titre: Re : Commande spawn
Posté par: Malak le 12 Décembre 2012, 09:14:09
Bonjour,

Sachant que strval = est le formatage d'une valeur texte en valeur numérique (exemple : "1 Hey" = 1)
Tu ne peut donc pas vérifier si il y a un contenu numérique dans ta variable proprio à moin que tu selectionne un joueur en ligne avec playerid. Dans ce cas tu peut faire sa
Code: (pawn) [Sélectionner]
proprio = strval(tmp);// essaye plutôt sa : proprio = ReturnUser(tmp); // si tu selectionne bien un joueur dans ta commande
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))


N'oublie pas aussi de vérifier si le joueur est bien en ligne avant de lancer le bout de code, sa permet d'éviter tout beug.

Malak ++

Titre: Re : Commande spawn
Posté par: Ashley11 le 12 Décembre 2012, 14:03:16
j'ai changé par

proprio = tmp; // Car le proprio n'est pas forcement un joueur valide
Mais j'ai un autre problème :

VehicleOwner[i] = proprio; // error 047: array sizes do not match, or destination array is too small
Titre: Re : Commande spawn
Posté par: Malak le 12 Décembre 2012, 15:27:43
Alors tu fait tout simplement

Code: (pawn) [Sélectionner]
new proprio[MAX_PLAYER_NAME];
proprio = strlen(tmp);
Titre: Re : Commande spawn
Posté par: Ashley11 le 12 Décembre 2012, 15:30:18
Ici, il n'y a pas d'erreur, j'affecte un string à un string
Code: (pawn) [Sélectionner]
proprio = tmp;
Mais ici :

Code: (pawn) [Sélectionner]
VehicleOwner[i] = proprio; // VehicleOwner[playerid]
Titre: Re : Commande spawn
Posté par: Infu le 12 Décembre 2012, 17:58:34
Je sais pas si c'est toi qui a ajouté le commentaire après ton code mais, la réponse est dedans.

Remplace le "" par  [playerid] :)
Titre: Re : Commande spawn
Posté par: Ashley11 le 12 Décembre 2012, 18:16:12
Oui, mais je suis trompé la définition exacte est :

Code: (pawn) [Sélectionner]
new VehicleOwner[MAX_DVEHICLES][MAX_PLAYER_NAME];
est l'erreur est ici

Code: (pawn) [Sélectionner]
VehicleOwner[i] = proprio; // // error 047: array sizes do not match, or destination array is too small
Pourtant MAX_DVEHICLES vaut 1000...
Titre: Re : Commande spawn
Posté par: Infu le 12 Décembre 2012, 19:03:24
Je sais pas du tout...

Essaye voir de changer en MAX_VEHICLE ou augmenter ta variable...?
Titre: Re : Commande spawn
Posté par: Ashley11 le 13 Décembre 2012, 00:01:12
Bonsoir, j'ai résolu en utilisant

Code: (pawn) [Sélectionner]
strcpy();
Merci pour tout !

++
Titre: Re : Commande spawn
Posté par: S!m le 13 Décembre 2012, 00:03:45
Salut,

le problème ne vient pas de la première dimension de ta variable.

Si tu veux éviter tout problème, utilise une des deux approches suivantes:

strins(VehicleOwner[i], proprio, 0);
format(VehicleOwner[i], MAX_PLAYER_NAME, "%s", proprio);

ces approches évitent les problèmes de ce genre puisqu'elles passent par des fonctions qui "cachent" le problème au script. Il faut toutefois faire attention à ce que les dimensions concordent.

strcpy fonctionne aussi pour faire la même chose.

++Sim++