SA-MP Forums Archive
diverses Checkpoints - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: diverses Checkpoints (/showthread.php?tid=193504)



diverses Checkpoints - BlackWolf120 - 26.11.2010

Hi forum,

ive got a problem i just cant solve.
I need some of these red checkpoints in game in order to create my gamemode.
My question is, how can i kind of differentitate between 2 or more CP's?
E.g. at the beginnig ive got 1 cp. After ive entered this first cp i got 2000$
Well this first cp gets disabled and the next one appears swomewhere else.
If im gonna to enter the second cp i want it to gove me 4000$, not only 2000$ like in the first one.
So how can i define what action or funktion is executed in a certain cp?

I'd be soo happy if someone of you scripting gods could help me.
Regards.


Re: diverses Checkpoints - JamesC - 26.11.2010

pawn Код:
// Top of script
new CheckPoint[MAX_PLAYERS]; // Creating the variable which would contain the ID of the CP is spawned for the player.

// OnPlayerConnect
CheckPoint[playerid] = 0; // Reseting the variable for new players

// OnPlayerEnterCheckpoint
switch(CheckPoint[playerid])
{
    case 1: { // Replace 1 with the ID of the created checkpoint (Add more cases if needed)
       
    }
}

// Bottom
stock SetPlayerCheckpointEx(playerid, Float:x, Float:y, Float:z, Float:size, ID) // Creating a new function that includes an ID parameter
{
    CheckPoint[playerid] = ID; // Setting the players variable to the ID of the created checkpoint.
    SetPlayerCheckpoint(playerid, x, y, z, size); // Creating the checkpoint.
}

// Example
CMD:cp(playerid, params[])
{
    SetPlayerCheckpointEx(playerid, 0.0, 0.0, 0.0, 5.0, 1337);
    return 1;
}

case 1337: {
    GivePlayerMoney(playerid, 1337);
}
Untested.
You don't need to create a custom function, but it just makes things easier.


Re: diverses Checkpoints - BlackWolf120 - 26.11.2010

hi,
thank u 2 for the answers.

@James C
thx, ur answer helped me alot! I also want to thank you y Less, but as a beginner i m able to understand things easier with code answers and examples.

But... How could i involve the teams to this case cp function?
E.g. there are 2 teams. If a member of team 1 enters the first cp there should appear a cp in the base of team 2.
If a member of team 2 enters the first cp, a second cp should appear, but in the base of team 1.
How could i do that? I hope that it is possible to understand this explanation.

P.s: Wow, didnt expect 2 answers that fast, great forum!!!

//edit code

this is how i defined my 2 teams:

[pwn]

new team[MAX_PLAYERS];

switch (classid)
{
case 0,1,2,3,4,5: //police
{
GameTextForPlayer(playerid, "~b~T-Zero", 500,5);
}

case 6,7,8,9,10,11: //terrorists
{
GameTextForPlayer(playerid, "~r~Burner", 500,5);
}
}

//teamsandteamcolors

//police

if (classid == 0)
{
team[playerid] = 1;
SetPlayerColor(playerid, 0x0000BBAA);
}


//and so on...

[/pwn]

Regards.


Re: diverses Checkpoints - JamesC - 26.11.2010

I'm assuming the first CP is the same for both teams, if so:

pawn Код:
case (FirstCP): {
    if(team[playerid] == 1) // If the player is part of Team 1
    {
        SetPlayerCheckpointEx(playerid, Base2_x, Base2_y, Base2_z, 5.0, ID); // Set a CP at the base of Team 2
    }
   
    if(team[playerid] == 2) // If the player is part of Team 2
    {
        SetPlayerCheckpointEx(playerid, Base1_x, Base1_y, Base1_z, 5.0, ID); // Set a CP at the base of Team 1
    }
}
PS: The tag is [pawn] not [pwn].


Re: diverses Checkpoints - BlackWolf120 - 26.11.2010

Wow,
unbelievable how easy everything can be when a pro teaches you
Really, im so happy that u help me.

mhhh, another question:

i did this function with a timer:

pawn Код:
forward Bombspawnpolice(playerid);

switch(CheckPoint[playerid])
{

case 0: {  //checkpoint 1

    if(team[playerid] == 1) // If the player is part of Team 1
    {
       SetTimer("Bombspawnpolice",15000,false);
    }


public Bombspawnpolice(playerid)
{
bomb = CreatePickup(1252, 3, 268.6314,79.7258,1001.0391);
SendClientMessage(playerid, 0x7CFC00AA, "Bomb has been created!! Start the countdown fast!! ( +2000$ )");
DisablePlayerCheckpoint(playerid);
GivePlayerMoney(playerid,2000);
new name[ 24 ], string[ 64 ];
GetPlayerName( playerid, name, 24 );
format( string, sizeof(string), "~y~%s has created the Bomb!", name );
GameTextForAll( string, 5000, 5 );
SetPlayerCheckpointEx(playerid, 268.6314,79.7258,1001.0391, 2.0, 1);

    return 1;
}
pawn Код:
public OnPlayerLeaveCheckpoint(playerid)
{
KillTimer(Bombspawnpolice);   //doesnt work: error 076: syntax error in the expression, or invalid function call

return ;
}


I want that the timer stops as soon as the player in the first cp leaves the cp.
It takes 15sec to create the 2nd cp and i want that u have to stay all the 15 sec in the cp otherwise the timer stops and has to start from the beginning after u have entered the cp again. Now u just can leave the cp after entered once and the timer goes on.
Ive tried it with killtimer (under onplayerleavecheckpoint) but it doesnt work.
Do u know how to fix this?


Regards.

//edit and sorry for the wrong pawn using.


Re: diverses Checkpoints - JamesC - 26.11.2010

SetTimer returns the ID of the newly created timer. To keep track of this ID between different functions, you need to:

pawn Код:
// Top of script
new BSPTimer;

// Enter Checkpoint
BSPTimer = SetTimer("Bombspawnpolice",15000,false);

// Leave Checkpoint
KillTimer(BSPTimer);



Re: diverses Checkpoints - BlackWolf120 - 26.11.2010

haha thx, is there something u dont know

well as i said, im really a noob at scripting yet, so please dont be angry about all the questions.
mhh, maybe ive got another question

pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
   

switch(CheckPoint[playerid])
{

case 0: {//checkpoint1

    if(team[playerid] == 1) // If the player is part of Team 1
    {
       SetTimer("Bombspawnpolice",15000,false);
    }
    if(team[playerid] == 2) // If the player is part of Team 2
    {
        SetTimer("Bombspawnterrorists",15000,false);
    }

 }

case 1: { //checkpoint2 in police base
 

    if(team[playerid] == 1) // If the player is part of Team 1
    {
      DisablePlayerCheckpoint(playerid);
      new name[ 24 ], string[ 64 ];
      GetPlayerName( playerid, name, 24 );
      format( string, sizeof(string), "~g~%s has aborted the countdown!!", name );
      GameTextForAll( string, 5000, 5 );
      SendClientMessage(playerid, 0x7CFC00AA, "Well done! Countdown aborted!! ( +2000$ )");
    }
    if(team[playerid] == 2) // If the player is part of Team 2
    {
        //here would be the actions for team 2 but for sure u know that better than me:p
    }

 }


   
    return 1; // in this line i get an error:  error 002: only a single statement (or expression) can follow each "case"
}
What am i doing wrong?

Regards.

P.s: no errors in case 0. (theres everything right in case0, its just for u to see the whole construction)

//edit: And is there a possibility that only a certain team is able to see a certain cp?


Re: diverses Checkpoints - JamesC - 26.11.2010

You need another } before return 1 to close the switch statement. Having good indentation always helps with keeping track of brackets.


Re: diverses Checkpoints - BlackWolf120 - 26.11.2010

I thank you soo much for ur help

Regards.


Re: diverses Checkpoints - BlackWolf120 - 26.11.2010

hi,

i had another little question:
anyone knows how to start a new round after the first one has been finished?
This is really important to me


regards.