Vice City Multiplayer
VC:MP 0.3 => mIRC/pawn Scripting => Topic started by: Pain on March 16, 2013, 10:36:25 am
-
OnPickedUp is not working
If picked up health will have $ 500
but don‘t have $ 500
-
Create a global variable.
new hpickup;
put in gamemodeinit
hpickup = AddStaticPickup(366, 1, x, y, z ); //Make sure you modify it to the location you want that pickup
add this on pickeduppickup
public OnPickedUp(pickupid, playerid)
{
if(pickupid == hpickup)
{
new Float:cash;
cash = GetPlayerMoney(playerid);
if(cash < 500 )
{
SendClientMessage(playerid, -1, "You don't have enough cash to use this heal pickup");
return 0;
}
else if( cash >= 500 )
{
GivePlayerMoney(playerid, -500);
SendClientMessage(playerid, -1, "You have been healed");
}
}
return 1;
}
-
in OnGameModeInit:
[pawn] AddStaticPickup(5, 431, X, Y, Z); // we have added pickup with id 5 and it's modelid - 431. Add your X, Y, Z coords[/pawn]
in OnPickedUp:
[pawn]
if(pickupid==5) // we check if pickup's id is 5.
{
new pcash = GetPlayerMoney(playerid); // we get player money though "pcash" variable.
new Float:hp; // we create a new float - hp.
GetPlayerHealth(playerid, hp); // we get player health, expressing it in "hp" which we created before.
if(hp < 100) // we check if player's hp < 100, this'll let us heal him only if his health's not 100.
{
if(pcash < 500) // we check if player doesn't have enough money ($500)
{
new str[256]; // if he's not, we make a new string,
format(str, sizeof(str), "You don't have $500. You got only $%d", pcash); // we set the 1st string format
SendClientMessage(playerid, 0xFF0000AA, str); // we send him formated string, which explains him that he's bum
}
else // else ( it means if he's got $500)
{
SetPlayerHealth(playerid, 100); // we set his health to 100 (restore).
SetPlayerMoney(playerid, pcash - 500); // we take a bit of his cash.
new str2[256]; // we make a new string, now "str2".
format(str2, sizeof(str2), "You have been healed for $500. You got now $%d", pcash - 500); // we set it's format.
SendClientMessage(playerid, 0xFFFFFFAA, str2); // we send him the 2nd formated string, which says that we healed him and took $500 from his pocket :)
}
return 1;
} // we lock the condition which calls function if he's got enough money or he's not.
else // else if his hp's 100
{
SendClientMessage(playerid, 0xFF0000AA, "You don't need to heal yourself"); // we send him a message that he's healthy
}
}
return 1;[/pawn]
Done!
:)
-
Well the same way... the only difference is that you made it a little more complicated and advanced.
-
hpickup = AddStaticPickup(366, 1, x, y, z ); //Make sure you modify it to the location you want that pickup
The correct syntax is: AddStaticPickup(pickupid, modelid, x, y, z);
-
i made the variable to remove confusion and anyways that will also work ;)
-
i made the variable to remove confusion and anyways that will also work ;)
How do you know if him have the same version of function or have the standard one ? You can't know that, so will be better to put the standard function.
-
i have 2 answers for that question.
1. In this case we know he don't have it
2. Someone who is scripting is not noob enough who dont even know that if he has already defined it or not... and if he already have then leave that step and if not then create it, Simple
-
OK