SA-MP Forums Archive
values and vehicle spawns - 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)
+--- Thread: values and vehicle spawns (/showthread.php?tid=619627)



values and vehicle spawns - MrCesar - 20.10.2016

Hello guys, I've made this cmd yesterday:
Код:
CMD:usecoca(playerid, params[])
{
	if(PlayerInfo[playerid][Cocaine] >=2)
	{
	    SendClientMessage(playerid, -1, "you just used 2 grams of cocaine restored 20 hp");
	    PlayerInfo[playerid][Cocaine] -= 2; //too stoned fix 2moro
     	new Float:health;
   		GetPlayerHealth(playerid,health);
    	if (health < 100)
    	{
        	SetPlayerHealth(playerid, health +15);
    	}
    	else if(health == 100)
    	{
    	    SendClientMessage(playerid, -1, "why use coca");
    	}
 	}
 	else SendClientMessage(playerid, -1, "you dont have enough coca");
 	return 1;
}
now it works fine, but if a player has 100 hp is still uses cocaine, and sends both messages e.g.


how do I fix this?

and another question I have is how to spawn vehicels with a timer? I think because I am using streamer plugin the map loads after I get to see the vehicles, and they all fall down into the water:



what I showed above is the vehicles as they spawn once I am near the map..anyway to fix this? thanks in advance!


EDIT: how do I remove that clock from the top? it really grinds my gears


Re: values and vehicle spawns - lackmail - 20.10.2016

you was sending the message of "you just used..." and PlayerInfo[playerid][Cocaine] -= 2; before checking the health thats why no matter whats your health is you will get the message and minus 2 cocaine as long you have 2 or more cocaine

use this:

Код:
CMD:usecoca(playerid, params[])
{
	if(PlayerInfo[playerid][Cocaine] >=2)
	{
		new Float:health;
   		GetPlayerHealth(playerid,health);
    	if (health < 100)
    	{
        	SetPlayerHealth(playerid, health +15);
        	PlayerInfo[playerid][Cocaine] -= 2;
			SendClientMessage(playerid, -1, "you just used 2 grams of cocaine restored 20 hp");
    	}
    	else if(health == 100)
    	{
    	    SendClientMessage(playerid, -1, "why use coca");
    	}
 	}
 	else SendClientMessage(playerid, -1, "you dont have enough coca");
 	return 1;
}
this is how you spawn vehicles using timer:
Код:
public OnGameModeInit()
{
    SetTimer("SpawnVehicle", 10000, false); // spawns vehicle after 10 seconds you can use this line in a command
}

forward SpawnVehicle();
public SpawnVehicle()
{
    CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, -1, -1, 60);
    /// add your vehicles here
}
but i am sure there is another way to solve this problem just wait for others to give their opinions


Re: values and vehicle spawns - MrCesar - 20.10.2016

Quote:
Originally Posted by lackmail
Посмотреть сообщение
you was sending the message of "you just used..." and PlayerInfo[playerid][Cocaine] -= 2; before checking the health thats why no matter whats your health is you will get the message and minus 2 cocaine as long you have 2 or more cocaine

use this:

Код:
CMD:usecoca(playerid, params[])
{
	if(PlayerInfo[playerid][Cocaine] >=2)
	{
		new Float:health;
   		GetPlayerHealth(playerid,health);
    	if (health < 100)
    	{
        	SetPlayerHealth(playerid, health +15);
        	PlayerInfo[playerid][Cocaine] -= 2;
			SendClientMessage(playerid, -1, "you just used 2 grams of cocaine restored 20 hp");
    	}
    	else if(health == 100)
    	{
    	    SendClientMessage(playerid, -1, "why use coca");
    	}
 	}
 	else SendClientMessage(playerid, -1, "you dont have enough coca");
 	return 1;
}
this is how you spawn vehicles using timer:
Код:
public OnGameModeInit()
{
    SetTimer("SpawnVehicle", 10000, false); // spawns vehicle after 10 seconds you can use this line in a command
}

forward SpawnVehicle();
public SpawnVehicle()
{
    CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, -1, -1, 60);
    /// add your vehicles here
}
but i am sure there is another way to solve this problem just wait for others to give their opinions
thanks for the coca fix! if I want to make it jobwise, I just need to add Job and my pInfo enum?
and check if his job == 1 (lets say smuggler) then only he will be able to smuggle coca?


Re: values and vehicle spawns - Threshold - 20.10.2016

PHP код:
CMD:usecoca(playeridparams[])
{
    if(
PlayerInfo[playerid][Cocaine] < 2) return SendClientMessage(playerid, -1"You don't have enough coca.");
    new 
Float:health;
    
GetPlayerHealth(playeridhealth);
    if(
health >= 100.0) return SendClientMessage(playerid, -1"Why are you using coca?");
    
SetPlayerHealth(playerid, ((health 15.0) >= 100.0) ? (100.0) : (health 15.0));
    
SendClientMessage(playerid, -1"You just used 2 grams of cocaine and restored 20 hp.");
    
PlayerInfo[playerid][Cocaine] -= 2//too stoned fix 2moro
    
return 1;

The original code would allow players to have up to 115 health.


Re: values and vehicle spawns - JohnBlaze1971 - 20.10.2016

Yes, if you want to add the command for 1 job and restrict it to other jobs then use enums.
For example, If you use pInfo[playerid][job] as your enum to get player's job, and your smuggler job is 1 then,
Код:
if(pInfo[playerid][job] != 1) return 0;
(or)
if(!pInfo[playerid][job] == 1) return 0;