Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: Inferno on Jan 19, 2021, 12:34 PM

Title: Custom Checkpoint Functions ( Count, Type, Creation, Deletion )
Post by: Inferno on Jan 19, 2021, 12:34 PM

Intro
QuoteThis custom snippet, will count the number of checkpoints created in the Server. You can also set its type to make it execute something based on its type instead of its ID


Functions
function iCreateCheckpoint( player, world, isSphere, pos, argb, radius ) // create a cp, its same as default one, just add an 'i' in start
{
CreateCheckpoint(player, world, isSphere, pos, argb, radius);
CheckpointCount++;
cpType[CheckpointCount] =  null;
print("Checkpoint Created, Count: "+CheckpointCount+"");
}

function iDeleteCheckpoint( checkpoint ) // delete a cp
{
cpType[checkpoint.ID] = null;
checkpoint.Remove();
CheckpointCount--;
print(" Checkpoint Removed, Count : "+CheckpointCount+" ");
}

function SetCheckpointType( checkpoint, type ) { // sets cp type
local cp = FindCheckpoint(checkpoint);
if(cp) {
cpType[cp.ID] = type;
print("Checkpoint ID :"+cp.ID+" type set to "+type+" ");
}
}


OnScriptLoad
CheckpointCount <- -1;
 cpType <- array(2000,null);




Example

// OnScriptLoad
iCreateCheckpoint( null, 0, true, Vector(90.697, 278.878, 21.7719), ARGB(255, 255, 255, 255), 2.2); // golf cp
iCreateCheckpoint( null, 0, true, Vector(87.4472, -1453.78, 10.5655), ARGB(255, 255, 255, 255), 2.2); // pole cp
SetCheckpointType( 0, "golf" ); //  sets type
SetCheckpointType( 1, "pole" ); // same

// OnCheckpointEntered

function onCheckpointEntered( player, checkpoint )
{
if (cpType[checkpoint.ID] == "golf") {
Message("[#ffffff] Golf Club ");
}
else if(cpType[checkpoint.ID] == "pole") {
Message("[#ffff11] Pole Club ");
}   
}



Note
Quote~ There is another alternative to count the checkpoints as well, but i lost that snippet.
~ The checkpoint count will only increase or decrease upon using these custom functions and not for default ones, same goes for the checkpoint type thing
~ You can add more classes to execute checkpoint functions based on other things than ID, i.e pos, color etc


Title: Re: Custom Checkpoint Functions ( Count, Type, Creation, Deletion )
Post by: Xmair on Jan 19, 2021, 12:52 PM
Please don't use the center tag on your code.