PDA

View Full Version : help - Simple checkpoint for repair


gotwarzone
07/03/2014, 04:28 PM
Hi. Can you please help me make a simple checkpoint for repair vehicle?

When a player with a vehicle land on a checkpoint. the vehicle will freeze and starts repairing. I was ******ing if there are some tuts but there are none.

Thanks!

Lajko1
07/03/2014, 07:49 PM
OnPlayerEnterCheckpoint - TogglePlayerControllable - SetVehicleHealth - GivePlayerMoney - done

gotwarzone
08/03/2014, 06:12 AM
Very well explained. Hope someone help me with a simple coding as well.

GrandParadise
08/03/2014, 06:21 AM
if(strcmp(cmdtext, "/repair", true)==0)
{
if(IsPlayerInCheckpoint(playerid))
{
if(IsPlayerInAnyVehicle(playerid))
{
Freeze(vehicleid);
SetTimerEx("Unfreeze", 5000, false, "i", playerid
}
else
{
SendClientMessage(playerid, red, "Error: You need to be in a vehicle to repair it!");
}
}
else
{
SendClientMessage(playerid, red, "Error: You are not in the checkpoint!");
}
return 1;
}

gotwarzone
08/03/2014, 06:32 AM
if(strcmp(cmdtext, "/repair", true)==0)
{
if(IsPlayerInCheckpoint(playerid))
{
if(IsPlayerInAnyVehicle(playerid))
{
RepairVehicle(GetPlayerVehicleID(playerid));
}
else
{
SendClientMessage(playerid, red, "Error: You need to be in a vehicle to repair it!");
}
}
else
{
SendClientMessage(playerid, red, "Error: You are not in the checkpoint!");
}
return 1;
}

Wow thanks +rep, and how about if I will make a message that will show only when he enter the repair checkpoint?

Let say I landed on the checkpoint and a message will appear "Press Alt Key to Repair your vehicle" and which is better textdraw or gametextforplay?

EDIT: also the repair will take 5 seconds

GrandParadise
08/03/2014, 06:35 AM
I'd rather use textdraw as it looks more professional.

gotwarzone
08/03/2014, 06:44 AM
Yeah right! Lol anyway the script you posted. Is the freeze forever? Can you add a timer after 5 seconds freeze then after the 6 seconds it will unfrozen.

ReD_HunTeR
08/03/2014, 06:49 AM
public OnPlayerSpawn(playerid)
{
SetPlayerCheckpoint(playerid, 0, 0, 0, 3.0); //fill the things...
return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
TogglePlayerControllable(playerid,0);
SetTimerEx("srepair",10000,0,"i",playerid);
return 1;
}

forward srepair(playerid);
public srepair(playerid)
{
TogglePlayerControllable(playerid,1);
RepairVehicle(GetPlayerVehicleID(playerid));
GameTextForPlayer(playerid,"~n~~g~Vehicle ~r~Repaired",3000,3);
return 1;
}

gotwarzone
08/03/2014, 07:06 AM
Thanks blackbomb you just bombed my world! I also like to ask something.

Do you think it's possible if I enter the repair checkpoint, my damaged vehicle will start repairing every seconds? Let say my vehicle hp is 500 (half of 1000 max hp) when I enter the checkpoint it will raise by 30hp each seconds? Without freezing the vehicle? then when I leave the repair checkpoint it will stop repairing.

gotwarzone
08/03/2014, 03:05 PM
Hi anyone?

Matess
08/03/2014, 03:20 PM
Well if someone enter CP run the timer which adds every second health to his car and kill it when he leave the CP.

gotwarzone
10/03/2014, 04:24 PM
Yes matess that is what I wanted. But please if anyone can make a demo script on how to do it can you please post it here?

Macronix
10/03/2014, 04:55 PM
Try this:


//OnPlayerEnterCheckpoint
if(IsPlayerInAnyVehicle(playerid))
{
SendClientMessage(playerid, -1, "Your vehicle is being repaired...");
}

//This in timer function:
new Float:vHealth;
GetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth);
SetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth + YOUR_REPAIR_VALUE);

gotwarzone
10/03/2014, 05:33 PM
Try this:


//OnPlayerEnterCheckpoint
if(IsPlayerInAnyVehicle(playerid))
{
SendClientMessage(playerid, -1, "Your vehicle is being repaired...");
}

//This in timer function:
new Float:vHealth;
GetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth);
SetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth + YOUR_REPAIR_VALUE);


thanks dear. but how about the timer repair every seconds?

Matess
10/03/2014, 05:46 PM
new timer[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
SetPlayerCheckpoint(playerid, 0, 0, 0, 3.0); //fill the things...
return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
if(IsPlayerInAnyVehicle(playerid))
{
SendClientMessage(playerid, -1, "Your vehicle is being repaired...");
timer[playerid] = SetTimerEx("srepair",1000,1,"i",playerid);
}
return 1;
}

forward srepair(playerid);
public srepair(playerid)
{
new Float:vHealth;
GetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth);
SetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth + 50.0);
return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
KillTimer(timer[playerid]);
return 1;
}

gotwarzone
10/03/2014, 05:50 PM
I don't see any checkpoint. why? im using this

SetPlayerCheckpoint(playerid, 1965.5537,1341.8009,15.4269, 3.0); im very very sure of the coordinates.

and im getting undefined symbol timer

timer[playerid] = SetTimerEx("srepair",1000,1,"i",playerid);

Matess
10/03/2014, 05:56 PM
Just look under onplayerspawn and replace it with your CP.

You must copy everything!

new timer[MAX_PLAYERS]; //sry

Macronix
10/03/2014, 05:58 PM
Are you close enough to the checkpoint? Where do you add the checkpoint?

gotwarzone
10/03/2014, 06:22 PM
Hi. I fixed the checkpoint not showing. what I did is I put the script in filterscript and when I moved it all in gamemode it is now appearing in map (red square)

But another problem with the repair. I use /dl to check the health of a vehicle the maximum is 1000. When I tried to hit a wall again and again (it start to make smoke out of the car), then after that I enter the checkpoint to make a vehicle repair. Yes the health is going up and I think its start repairing. But the smoke from the vehicle didn't remove and the health repair didn't stop regenerating. the max is 1000 and its going up to 3000+

Matess
10/03/2014, 06:28 PM
forward srepair(playerid);
public srepair(playerid)
{
new Float:vHealth;
GetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth);
if(vHealth >= 1000.0)
{
KillTimer(timer[playerid]);
RepairVehicle(GetPlayerVehicleID(playerid));
return 1;
}
SetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth + 50.0);
return 1;
}

gotwarzone
10/03/2014, 06:37 PM
forward srepair(playerid);
public srepair(playerid)
{
new Float:vHealth;
GetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth);
if(vHealth >= 1000.0)
{
KillTimer(timer[playerid]);
RepairVehicle(GetPlayerVehicleID(playerid));
return 1;
}
SetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth + 50.0);
return 1;
}


You are just amazing man! yes all working like a charm. anyways, one last question. everytime I enter the repair checkpoint even my vehicle health is full the message "Your vehicle is being repaired..." still showing.

how do I add like "Your vehicle is already fully repaired" only show this message when I enter the checkpoint only if my vehicle health is full?

also is that possible after I have fully repaired my vehicle from the CP then show message "Vehicle finished repairing" something like that?

Matess
10/03/2014, 06:50 PM
new timer[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
SetPlayerCheckpoint(playerid, 0, 0, 0, 3.0); //fill the things...
return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
if(IsPlayerInAnyVehicle(playerid))
{
new Float:vHealth;
GetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth);
if(vHealth >= 1000.0) return SendClientMessage(playerid, -1, "Your vehicle is already fully repaired");
SendClientMessage(playerid, -1, "Your vehicle is being repaired...");
timer[playerid] = SetTimerEx("srepair",1000,1,"i",playerid);
}
return 1;
}

forward srepair(playerid);
public srepair(playerid)
{
new Float:vHealth;
GetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth);
if(vHealth >= 1000.0)
{
KillTimer(timer[playerid]);
RepairVehicle(GetPlayerVehicleID(playerid));
SendClientMessage(playerid, -1, "Vehicle finished repairing");
return 1;
}
SetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth + 50.0);
return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
KillTimer(timer[playerid]);
return 1;
}

gotwarzone
10/03/2014, 07:37 PM
new timer[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
SetPlayerCheckpoint(playerid, 0, 0, 0, 3.0); //fill the things...
return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
if(IsPlayerInAnyVehicle(playerid))
{
new Float:vHealth;
GetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth);
if(vHealth >= 1000.0) return SendClientMessage(playerid, -1, "Your vehicle is already fully repaired");
SendClientMessage(playerid, -1, "Your vehicle is being repaired...");
timer[playerid] = SetTimerEx("srepair",1000,1,"i",playerid);
}
return 1;
}

forward srepair(playerid);
public srepair(playerid)
{
new Float:vHealth;
GetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth);
if(vHealth >= 1000.0)
{
KillTimer(timer[playerid]);
RepairVehicle(GetPlayerVehicleID(playerid));
SendClientMessage(playerid, -1, "Vehicle finished repairing");
return 1;
}
SetVehicleHealth(GetPlayerVehicleID(playerid),vHea lth + 50.0);
return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
KillTimer(timer[playerid]);
return 1;
}


Thanks brother! appreciate your help if only I can give you reps each time you reply lol.

gotwarzone
10/03/2014, 07:59 PM
Does anyone know how to replace "SetPlayerCheckpoint" to a simple checkpoint streamer? coz SetPlayerCheckpoint shows all over the map and it looks like important mission to be done. lol.

Macronix
10/03/2014, 08:01 PM
You can use icognito's streamer plugin (http://forum.sa-mp.com/showthread.php?t=102865) and use CreateDynamicCP ;)

gotwarzone
10/03/2014, 08:21 PM
You can use icognito's streamer plugin (http://forum.sa-mp.com/showthread.php?t=102865) and use CreateDynamicCP ;)

thanks mate! got it working!