spawn car/nrg on command
#1

the problem is when i do /inf many times i get loads of cars and after [10] seconds they suppose to disappear if nobody is driving them but they respawn on the same place.

can someone help me to make only one car PER person so if he spawned a car already and types /inf or /nrg the old car disappears.

here is my code:

public OnPlayerCommandText(playerid, cmdtext[])
{
new Float:Pos[4],inf;
new Float:Pose[4],nrg;

if(!strcmp(cmdtext,"/inf",true))
{
GetPlayerPos(playerid,Pos[1],Pos[2],Pos[3]);
inf=CreateVehicle(411,Pos[1],Pos[2],Pos[3],0,-1,-1,10);
PutPlayerInVehicle(playerid,inf, 0);
SendClientMessage(playerid,0xFF641AFF,"SERVER: You have Spawned An Infernus.");
return 1;
}
if(!strcmp(cmdtext,"/nrg",true))
{
GetPlayerPos(playerid,Pose[1],Pose[2],Pose[3]);
nrg=CreateVehicle(522,Pose[1],Pose[2],Pose[3],0,-1,-1,10);
PutPlayerInVehicle(playerid,nrg, 0);
SendClientMessage(playerid,0xFF641AFF,"SERVER: You have Spawned An NRG-500.");
return 1;
}
return 0;
}

thank you!
Reply
#2

Like this (Sorry for the bad indentation)
BTW: Your original code was not meant for multiple players, now it is
Код:
new inf[MAX_PLAYERS]; // Declared here so it's a constant
new nrg[MAX_PLAYERS];

new Float:Pos[MAX_PLAYERS][4]; // You only need to declare one, not two

public OnPlayerCommandText(playerid, cmdtext[])
{
  if(!strcmp(cmdtext,"/inf",true))
  {
    DestroyVehicle(inf[playerid]);
     GetPlayerPos(playerid,Pos[playerid][1],Pos[playerid][2],Pos[playerid][3]);
     inf[playerid]=CreateVehicle(411,Pos[playerid][1],Pos[playerid][2],Pos[playerid][3],0,-1,-1,10);
     PutPlayerInVehicle(playerid,inf[playerid], 0);
    SendClientMessage(playerid,0xFF641AFF,"SERVER: You have Spawned An Infernus.");
     return 1;
  }
  if(!strcmp(cmdtext,"/nrg",true))
  {
   	DestroyVehicle(nrg[playerid]);
   	GetPlayerPos(playerid,Pos[playerid][1],Pos[playerid][2],Pos[playerid][3]);
     nrg[playerid]=CreateVehicle(522,Pos[playerid][1],Pos[playerid][2],Pos[playerid][3],0,-1,-1,10);
     PutPlayerInVehicle(playerid,nrg[playerid], 0);
    SendClientMessage(playerid,0xFF641AFF,"SERVER: You have Spawned An NRG-500.");
   return 1;
  }
  return 0;
}
Reply
#3

thank you man
btw your clock is awesome! our server uses it :P
Reply
#4

Quote:
Originally Posted by jamesbond007
thank you man
btw your clock is awesome! our server uses it :P
Wow, thanks man, and no problem!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)