#1

i have no script and i dont want it made for me but i want to be pointed in the right direction

i want to know how to make a script that when u run out of ammo it sends a message to the player saying you Are Out Of Ammo then the player type's /reload and it restores the player's ammo of the gun he is holding at the moment. if u can show me an example or point me in the right direction


regards.

[Nuclear]Phoebe.
Reply
#2

I would try to create a very frequent timer (or maybe OnPlayerUpdate) and a boolean like bool:ToldOutOfAmmo[MAX_PLAYERS];
Every time the timer passing you check wether or not the player has a weapon (just check his weapon-id) and then GetPlayerAmmo. If it's 0 check if ToldOutOfAmmo is true, else send a message to him and set it to true.
For the /reload just use SetPlayerAmmo then.
Hope it helped.
Reply
#3

ok i get /reload but i dont get the rest
Reply
#4

You could try using https://sampwiki.blast.hk/wiki/GetPlayerWeaponState with one of these: https://sampwiki.blast.hk/wiki/Weapon_States
Reply
#5

ive made my reload cmd but i cant grasp the out of bullets thing
Reply
#6

pawn Код:
new bool:ToldOutOfAmmo[MAX_PLAYERS]=false;

// Under OnPlayerUpdate:
if(GetPlayerWeaponState(playerid) == 0)
{
if(ToldOutOfAmmo[playerid] == false)
{
ToldOutOfAmmo[playerid] = true;
SendClientMessage(playerid, COLOR_RED, "You're out of ammo. Type /reload");
}
}
Used WeaponStates from the link Vince posted. Something like this is what you can do.
Of course you have to reset the boolean on your /reload command.
Reply
#7

ty Dude
Reply
#8

but wouldn't it when u have no ammo remove the gun from ur hand?
Reply
#9

ResetPlayerWeapons(playerid);
Reply
#10

no dude i dont want it to remove the weapon
Reply
#11

@Bella: Good question, haven't used weapons in gta a long time now... You could check for WeaponState 2 instead of 1 (Last bullet instead of empty weapon) and save the weaponid in a PVar for the player. and with /reload the weapon saved within the PVar gets reloaded.
Reply
#12

confused already help me on this one
Reply
#13

Of course
pawn Код:
new bool:ToldOutOfAmmo[MAX_PLAYERS]=false;

//OnPlayerCommandText
if(!strcmp(cmdtext, "/reload", true) == 0)
{
if(GetPVarInt(playerid,"weaponid") != 0)
{
GivePlayerWeapon(playerid, GetPVarInt(playerid,"weaponid"), 100); // Give the player the weapon + ammo
ToldOutOfAmmo[playerid]=false; // Reset out of ammo message
SetPVarInt(playerid,"weaponid",0) // Reset weaponid
SendClientMessage(playerid,COLOR_RED,"Weapon reloaded.");
}
else SendClientMessage(playerid,COLOR_RED,"You are not out of ammo.");
return 1;
}

// Under OnPlayerUpdate
if(GetPlayerWeaponState(playerid) == 1)
{
if(ToldOutOfAmmo[playerid] == false)
{
ToldOutOfAmmo[playerid] = true;
SetPVarInt(playerid,"weaponid",GetPlayerWeapon(playerid));
SendClientMessage(playerid, COLOR_RED, "You're out of ammo. Type /reload");
}
}
I think this is all you wanted to know and hope it helped
Reply
#14

thanks dude!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)