Need help with a function
#1

Hi,
I'm currently working on an special edition of Yagu's Race Filterscript again, because I lost my old one.
So here is my function:

Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
	if(RaceParticipant[playerid]>0)
	{
	if (EnableRespawn == 1)
	{
		new currentvehicle = (GetPlayerVehicleID(playerid));
		new lastCP = (CurrentCheckpoint[playerid]-1);
		DestroyVehicle(currentvehicle);
		SetPlayerHealth(playerid, 0);
		SetRaceCheckpoint(playerid,lastCP,CurrentCheckpoint[playerid]);
		RespawnTimer = SetTimer("RespawnPlayerInVehicle", RespawnDelay, false);
		RespawnPlayerInVehicle(playerid, currentvehicle);
	}
	}
  return 1;
}

stock RespawnPlayerInVehicle(playerid, vehicleid)
{
	new lastCP = (CurrentCheckpoint[playerid]-1);
	SpawnPlayer(playerid);
	SetPlayerPos(playerid, lastCP);
	CreateVehicle(currentvehicle, lastCP, 2, 4, 600);
	PutPlayerInVehicle(playerid, currentvehicle, 0);
	KillTimer(RespawnTimer);
}
I get this error two times:
Undefined symbol "currentvehicle"
Both in the RespawnPlayerInVehicle function.
My problem is to get the variable defined in OnPlayerExitVehicle, into RespawnPlayerInVehicle.
Can it be done, or is there a workarround?
There is a new problem. Look last post...
Reply
#2

put somewhere on the top of the script (global variable):
pawn Код:
CurrentVehicle[MAX_PLAYERS]
and use it in your function and callback:
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(RaceParticipant[playerid]>0)
    {
    if (EnableRespawn == 1)
    {
        CurrentVehicle[playerid] = vehicleid;
        new lastCP = (CurrentCheckpoint[playerid]-1);
        DestroyVehicle(vehicleid);
        SetPlayerHealth(playerid, 0);
        SetRaceCheckpoint(playerid,lastCP,CurrentCheckpoint[playerid]);
        RespawnTimer = SetTimer("RespawnPlayerInVehicle", RespawnDelay, false);
        RespawnPlayerInVehicle(playerid, CurrentVehicle[playerid] );
    }
    }
  return 1;
}

stock RespawnPlayerInVehicle(playerid, vehicleid)
{
    new lastCP = (CurrentCheckpoint[playerid]-1);
    SpawnPlayer(playerid);
    SetPlayerPos(playerid, lastCP);
    CreateVehicle(vehicleid , lastCP, 2, 4, 600);
    PutPlayerInVehicle(playerid, vehicleid, 0);
    KillTimer(RespawnTimer);
}
-----------------------

oh I've just looked more closely at your code.... you need vehicle MODEL, not the ID, also theres no need to store player vehicle model since your RespawnPlayerVehicle has model parameter (if you don't use its model anywhere else), so thy this:
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(RaceParticipant[playerid]>0)
    {
      if (EnableRespawn == 1)
      {
        new lastCP = (CurrentCheckpoint[playerid]-1);      
        SetPlayerHealth(playerid, 0.0);
        SetRaceCheckpoint(playerid,lastCP,CurrentCheckpoint[playerid]);
        RespawnTimer = SetTimerEx("RespawnPlayerInVehicle", RespawnDelay, false, "ii", playerid, GetVehicleModel(vehicleid));
         DestroyVehicle(vehicleid);
        // RespawnPlayerInVehicle(playerid, CurrentVehicle[playerid] ); why do you do it twice?
      }
    }
  return 1;
}

stock RespawnPlayerInVehicle(playerid, vehicleid)
{
    new lastCP = (CurrentCheckpoint[playerid]-1);
    new vehicleid = CreateVehicle(model, /*here should be x, y and z, not cp id */, 2, 4, 600);
    SpawnPlayer(playerid);
    SetPlayerPos(playerid, /* and here too */);
    PutPlayerInVehicle(playerid, vehicleid, 0);
    KillTimer(RespawnTimer);
}

Reply
#3

[quote=ZeeX ]
put somewhere on the top of the script (global variable):
pawn Код:
CurrentVehicle[MAX_PLAYERS]
Well except for this:
pawn Код:
new CurrentVehicle[MAX_PLAYERS];
Oke, now i've got this problem:
Number of arguments, does not match definition.
I think the problem is that the variable lastCP does not only save the the coords for the last, but for the next one too. How do I get only the first one?
Reply
#4

I guess there is a checkpoint array which stores their coords and LastCP is the index of some checkpoint, and you can extract its coords using that index.
Reply
#5

Quote:
Originally Posted by ZeeX
I guess there is a checkpoint array which stores their coords and LastCP is the index of some checkpoint, and you can extract its coords using that index.
The races are saved in files like this:
Код:
YRACE 1 Yagu 1 2
Yagu 227212 Yagu 233628 Yaguslave 372568 A 0 A 0
Yagu 112007 Yagu 112784 Yagu 115205 Yagu 120844 Yaguslave 127753
2096.481689 834.807189 6.446568
2466.802001 835.230346 6.441473
2725.932861 1182.561035 6.440519
2725.099365 2293.141113 6.440557
2545.458984 2588.155761 4.565608
2023.114746 2565.392822 6.498682
1326.486450 2451.088134 6.442695
1207.436279 2045.341796 6.444301
1214.165039 994.541076 6.518639
1976.803100 834.880798 6.445075
Reply
#6

OK, yrace has Float:RaceCheckpoints[MAX_RACECHECKPOINTS][3] - this is checkpoint array.
And are you sure you need to kill player, destroy his car and spawn him? Why not just put him back in the car?
Reply
#7

Quote:
Originally Posted by ZeeX
OK, yrace has Float:RaceCheckpoints[MAX_RACECHECKPOINTS][3] - this is checkpoint array.
And are you sure you need to kill player, destroy his car and spawn him? Why not just put him back in the car?
Yes, I'm sure, because I want the player to respawn at the checkpoint he was before, in the same vehicle. It's not about keeping him in the vehicle. I want the player to have an emergency solution, if he may flip over or he falls in the water. Just like in MTA: DM Race...
Reply
#8

Oke after a lot of fail's, I've managed to get the script working...
...there is jsut one thing that doesn't work. The player should be frozen for a specific amount of time. This works, but he isn't unfrozen after that time.
Here what I put on top of the script:
pawn Код:
new RespawnDelay = 100;   //The time the player will be frozen after respawned in ms.
new RespawnTimer;            //DO NOT CHANGE!!!
And here the functions:
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
if(RaceParticipant[playerid] == 4)
{
  if (EnableRespawn == 1)
  {
        new model = (GetVehicleModel(vehicleid));
        SetPlayerHealth(playerid, 100.0);
        SetRaceCheckpoint(playerid, CurrentCheckpoint[playerid]-1 ,CurrentCheckpoint[playerid]);
        DestroyVehicle(vehicleid);
        SetPlayerPos(playerid, lastCPx, lastCPy, lastCPz);
        new currentvehicleID = CreateVehicle(model, lastCPx, lastCPy, lastCPz, lastCPa, 2, 4, 600);
        PutPlayerInVehicle(playerid, currentvehicleID, 0);
        RespawnTimer = SetTimer("RespawnFreeze", RespawnDelay, false);
        TogglePlayerControllable(playerid,0);
  }
}
return 1;
}

stock RespawnFreeze(playerid)
{
    TogglePlayerControllable(playerid,1);
    KillTimer(RespawnTimer);
}
Everything else works fine.
Reply
#9

Timers only work with public functions, so:
pawn Код:
forward RespawnFreeze(playerid);

public RespawnFreeze(playerid)
{
    TogglePlayerControllable(playerid,1);
    KillTimer(RespawnTimer);
}
Reply
#10

Ty, it works!
Ehhm, one more question:
Is it possible to give the vehicle the same colors it had?
Reply
#11

Well, I don't like to say that, but how do I call the function whenever a player presses the button to enter/exit vehicle?
I looked at this and this, but I don't understand it...

Here are the complete functions again:
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
if(RaceParticipant[playerid] == 4)
{
  if (EnableRespawn == 1)
  {
        new model = (GetVehicleModel(vehicleid));
        SetPlayerHealth(playerid, 100.0);
        SetRaceCheckpoint(playerid, CurrentCheckpoint[playerid],CurrentCheckpoint[playerid]+1);
        DestroyVehicle(vehicleid);
        SetPlayerPos(playerid, lastCPx, lastCPy, lastCPz);
        new currentvehicleID = CreateVehicle(model, lastCPx, lastCPy, lastCPz, lastCPa, 2, 4, 600);
        PutPlayerInVehicle(playerid, currentvehicleID, 0);
        RespawnTimer = SetTimer("RespawnFreeze", RespawnDelay, false);
        TogglePlayerControllable(playerid,0);
  }
}
return 1;
}

public RespawnFreeze(playerid)
{
    TogglePlayerControllable(playerid,1);
    KillTimer(RespawnTimer);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)