Array Error - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Array Error (
/showthread.php?tid=521296)
Array Error -
ridhoswasta - 22.06.2014
Код HTML:
F:\CNR - RP\gamemodes\arcnr2p.pwn(2136) : error 006: must be assigned to an array
Код HTML:
for(new v=0; v<MAX_VEHICLES; v++)
{
VehicleInfo[v][bought] = pname; << this line
VehicleInfo[v][stolen] =0;
VehicleInfo[v][bombed] =0;
}
Re: Array Error -
Konstantinos - 22.06.2014
pawn Код:
strcpy(VehicleInfo[v][bought], pname, MAX_PLAYER_NAME);
pawn Код:
#define strcpy(%0,%1) strcat((%0[0] = '\0', %0), %1)
Re: Array Error -
ridhoswasta - 22.06.2014
where i can put that?
Re: Array Error -
Konstantinos - 22.06.2014
Add the macro somewhere in your script and replace:
pawn Код:
VehicleInfo[v][bought] = pname;
with this:
pawn Код:
strcpy(VehicleInfo[v][bought], pname, MAX_PLAYER_NAME);
Re: Array Error -
ridhoswasta - 22.06.2014
thank you so much sir!
Re: Array Error -
ridhoswasta - 22.06.2014
Код HTML:
F:\CNR - RP\gamemodes\arcnr2p.pwn(2136) : error 001: expected token: ")", but found "["
F:\CNR - RP\gamemodes\arcnr2p.pwn(2136) : warning 215: expression has no effect
F:\CNR - RP\gamemodes\arcnr2p.pwn(2136) : error 001: expected token: ";", but found "]"
F:\CNR - RP\gamemodes\arcnr2p.pwn(2136) : error 029: invalid expression, assumed zero
F:\CNR - RP\gamemodes\arcnr2p.pwn(2136) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
4 Errors.
Whats the problem?
Re: Array Error -
Konstantinos - 22.06.2014
In the enum used for VehicleInfo array, make "bought" an array with size of MAX_PLAYER_NAME:
pawn Код:
// in the enum:
bought[MAX_PLAYER_NAME] // add a comma if it's not last.
Re: Array Error -
ridhoswasta - 22.06.2014
Thanks !
Re: Array Error -
ridhoswasta - 22.06.2014
Код HTML:
F:\CNR - RP\gamemodes\arcnr2p.pwn(3138) : error 033: array must be indexed (variable "pname")
Код HTML:
public OnVehicleDeath(vehicleid, killerid)
{
for(new i = 0; i < MAX_PLAYERS; i++){
new pname[24];
GetPlayerName(i,pname,sizeof(pname));
if(VehicleInfo[vehicleid][bought] == pname) << this line?
{
SendClientMessage(VehicleInfo[vehicleid][bought],COLOR_ERROR,"The car your purchased from Otto's Cars has been destroyed.");
DestroyVehicle(vehicleid);
}
VehicleInfo[vehicleid][bought] = 999;
VehicleInfo[vehicleid][stolen] =0;
VehicleInfo[vehicleid][bombed] =0;
}
return 1;
}
Re: Array Error -
Konstantinos - 22.06.2014
You cannot use "bought" for both owner's name and price. Use another name for the price and use strcmp to compare strings:
pawn Код:
if (!strcmp(VehicleInfo[vehicleid][bought], pname, true, MAX_PLAYER_NAME))
and because strcmp returns 0 if one of them is NULL you can prevent it by doing:
pawn Код:
if (!isnull(VehicleInfo[vehicleid][bought]) && !strcmp(VehicleInfo[vehicleid][bought], pname, true, MAX_PLAYER_NAME))
and as I said before, use another name for the price here:
pawn Код:
VehicleInfo[vehicleid][bought] = 999;
or whatever it is anyways.