Temp godmode at spawn?
#1

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?
Reply
#2

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")
Reply
#3

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;
}
Reply
#4

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;
}
Reply
#5

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
Reply
#6

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;
}
Reply
#7

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
Reply
#8

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.
Reply
#9

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.
Reply
#10

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)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)