SA-MP Forums Archive
Temp godmode at spawn? - 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: Temp godmode at spawn? (/showthread.php?tid=122221)



Temp godmode at spawn? - biltong - 20.01.2010

I'm an absolute beginner when it comes to coding, but I have thrown a few bits and pieces together to make a script for me and some friends to freeroam on. I'd like to add a 30 second godmode when a player spawns since sometimes spawnkills are so tempting. Right now this is what my spawn code looks like:

Код:
public OnPlayerSpawn(playerid)
{
	GivePlayerMoney(playerid, PocketMoney);
	SetPlayerHealth(playerid, 100000.0);
	SetTimer("stopgod", 30000,0);
	SendClientMessage(playerid, COLOR_RED, "You are invulnerable for 30 seconds after spawning to prevent spawncamping.");
	return 1;
}
I don't know what to do from there. Suggestions?


Re: Temp godmode at spawn? - Joe Staff - 20.01.2010

You're close. What's wrong here is that you're using SetTimer, and not SetTimerEx. The difference is that SetTimerEx can send parameters to the function that you're using. So if your function looks like this:
pawn Код:
public stopgod(playerid)
{
  SetPlayerHealth(playerid,100.0);
  return 1;
}
Your 'SetTimerEx' execution has to look like this:
pawn Код:
SetTimerEx("stopgod",30000,0,"i",playerid);//i = integer (8), f = float (8.0), s = string ("8")



Re: Temp godmode at spawn? - biltong - 23.01.2010

Thanks!

Will report back on progress.

EDIT: How would I go about integrating that into my code? I made another function like so:

Код:
public OnPlayerSpawn(playerid)
{
	GivePlayerMoney(playerid, PocketMoney);
	SetPlayerHealth(playerid, 100000.0);
	SetTimerEx("stopgod", 30000,0);
	SendClientMessage(playerid, COLOR_RED, "You are invulnerable for 30 seconds after spawning to prevent spawncamping.");
	return 1;
}
//---------------------------------------------------------
public stopgod(playerid)
{
	SetPlayerHealth(playerid, 100.0);
	return 1;
}



Re: Temp godmode at spawn? - llama - 23.01.2010

Quote:
Originally Posted by biltong
Thanks!

Will report back on progress.

EDIT: How would I go about integrating that into my code? I made another function like so:

pawn Код:
public OnPlayerSpawn(playerid)
{
    GivePlayerMoney(playerid, PocketMoney);
    SetPlayerHealth(playerid, 100000.0);
    SetTimerEx("stopgod", 30000, 0, "%i", playerid);
    SendClientMessage(playerid, COLOR_RED, "You are invulnerable for 30 seconds after spawning to prevent spawncamping.");
    return 1;
}
//---------------------------------------------------------
public stopgod(playerid)
{
    SetPlayerHealth(playerid, 100.0);
    return 1;
}



Re: Temp godmode at spawn? - biltong - 23.01.2010

Thanks, it's compiled and working now

One last thing:

Код:
public OnPlayerCommandText(playerid, cmdtext[0])
{
	{
  	if (strcmp("/kill", cmdtext, true, 5) == 0)
  	{
    	SetPlayerHealth(playerid, 0.0);
    	return 1;
  		}
  
  	if (strcmp("/r", cmdtext, true))
  		{
    	new vehicleid = GetPlayerVehicleID(playerid);
    	RepairVehicle(vehicleid);
    	return 1;
		}
		else
		{
		  return SendClientMessage(playerid,COLOR_RED, "You're not in a vehicle!");
		}
	}
	return 1; //EDIT: I keep getting an unreachable code warning here. Why is it saying that?
}
Those are my two little commands, /kill works but /r doesn't, it always says that I'm not in a vehicle, even though I am when I try use it. Not sure how to fix that

Halp plz


Re: Temp godmode at spawn? - llama - 23.01.2010

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[0])
{
    if (strcmp("/kill", cmdtext, true, 5) == 0)
    {
     SetPlayerHealth(playerid, 0.0);
     return 1;
    }
 
    if (strcmp("/r", cmdtext, true))
    {
     new vehicleid = GetPlayerVehicleID(playerid);
      if(IsPlayerInAnyVehicle(playerid) RepairVehicle(vehicleid);
      else SendClientMessage(playerid, COLOR_RED, "You are not in a vehicle!");
     return 1;
    }
    return 0;
}



Re: Temp godmode at spawn? - biltong - 23.01.2010

I'd kiss you if I could. But:

Код:
if(IsPlayerInAnyVehicle(playerid)) RepairVehicle(vehicleid);
was missing a ) after the playerid. Was one thing I could fix

Many thanks


Re: Temp godmode at spawn? - llama - 23.01.2010

Quote:
Originally Posted by biltong
I'd kiss you if I could. But:

Код:
if(IsPlayerInAnyVehicle(playerid)) RepairVehicle(vehicleid);
was missing a ) after the playerid. Was one thing I could fix

Many thanks
Ah, simple mistake as I'm tired. Heh.


Re: Temp godmode at spawn? - bluray - 23.01.2010

one little thing not really important but to avoid passengers using /r and fixing others cars, (unless u want it like that)
replace the IsPlayeInAnyVehicle, with PState == PLAYER_STATE_DRIVER. but u cant just copy and past that needs to be defined and so on, but it saves annoying passengers.


Re: Temp godmode at spawn? - llama - 23.01.2010

Quote:
Originally Posted by bluray
one little thing not really important but to avoid passengers using /r and fixing others cars, (unless u want it like that)
replace the IsPlayeInAnyVehicle, with PState == PLAYER_STATE_DRIVER. but u cant just copy and past that needs to be defined and so on, but it saves annoying passengers.
No definitions required:

pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)