Author Topic: [old topic] Headcrab  (Read 15275 times)

Elistor

  • Newbie
  • *
  • Posts: 7
    • View Profile
[old topic] Headcrab
« on: May 27, 2010, 03:32:11 PM »
Headcrab race
Beta version

Require SDKHooks

  • 50% of HP on spawn.
  • Knife only race.
  • White headcrab model for CT, and black for T.


Skill 1 - Power legs
This is longjump. When level skill higher, then longjump is biggest.

Skill 2 - Four legs
Low gravity.
  • Level 1 - To 90%
  • Level 2 - To 80%
  • Level 3 - To 70%
  • Level 4 - To 60%


Race code:
Code: [Select]
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

#include "War3Source/War3Source_Interface"

new raceID;

public Plugin:myinfo =
{
name = "War3Source Race - Headcrab",
author = "Vladislav Dolgov",
description = "Headcrab race for War3Source.",
version = "1.0.0.0",
url = "http://elistor.ru/"
};


public OnWar3PluginReady()
{
raceID=War3_CreateRace("Headcrab", "headcrab",
"You being a headcrab!", "You being a headrab when he die or respawn.",
"Power legs", "Long jump.",
"Four legs", "Low gravity.",
"No skill", "No skill",
"No skill", "No skill");
}

public OnPluginStart()
{
HookEvent("player_spawn", Event_PlayerSpawn);
HookEvent("player_jump", Event_PlayerJump);
}

public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
MarkNativeAsOptional("SDKHook");
MarkNativeAsOptional("SDKUnhook");
return APLRes_Success;
}

public OnClientPutInServer(client)
{
SDKHook(client, SDKHook_WeaponCanUse, OnWeaponCanUse);
}

public Action:OnWeaponCanUse(client, weapon)
{
decl String:name[64];
GetEdictClassname(weapon, name, sizeof(name));

if(StrEqual(name, "weapon_knife", false))
return Plugin_Continue;

return Plugin_Handled;
}

public OnMapStart()
{
PrecacheModel("models/headcrab.mdl", true);
PrecacheModel("models/headcrabblack.mdl", true);
}
public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (client > 0)
{
new race = War3_GetRace(client);
if (race == raceID)
{
SetEntityHealth(client, 50);

if(GetClientTeam(client) == 3)
SetEntityModel(client, "models/headcrab.mdl");
else
SetEntityModel(client, "models/headcrabblack.mdl");

new skill3_fourlegs = War3_GetSkillLevel(client, race, 1);
new Float:gravity = 1.00;
switch (skill3_fourlegs)
{
case 0:
gravity = 1.00;
case 1:
gravity = 0.90;
case 2:
gravity = 0.80;
case 3:
gravity = 0.70;
case 4:
gravity = 0.60;
}
War3_SetMinGravity(client, gravity);
}
}
}

public OnSkillLevelChanged(client, race, skill, oldskilllevel, newskilllevel)
{
if (client > 0)
{
if (race == raceID && skill == 1)
{
new Float:gravity = 1.00;
switch (newskilllevel)
{
case 0:
gravity = 1.00;
case 1:
gravity = 0.90;
case 2:
gravity = 0.80;
case 3:
gravity = 0.70;
case 4:
gravity = 0.60;
}
War3_SetMinGravity(client, gravity);
}
}
}

public OnRaceSelected(client, oldrace, newrace)
{
if(newrace != raceID)
{
SetEntityHealth(client, 100);
War3_SetMinGravity(client, 1.00);
}
}

public Event_PlayerJump(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event,"userid"));
if (client > 0)
{
new race = War3_GetRace(client);
if (race == raceID)
{
new skill2_longjump = War3_GetSkillLevel(client, race, 0);
new Float:long_push = 1.00;
switch (skill2_longjump)
{
case 0:
long_push = 1.00;
case 1:
long_push = 1.05;
case 2:
long_push = 1.10;
case 3:
long_push = 1.15;
case 4:
long_push = 1.20;
}

if (skill2_longjump > 0)
{
new v_0 = FindSendPropOffs("CBasePlayer","m_vecVelocity[0]");
new v_1 = FindSendPropOffs("CBasePlayer","m_vecVelocity[1]");
new v_b = FindSendPropOffs("CBasePlayer","m_vecBaseVelocity");
new Float:finalvec[3];
finalvec[0] = GetEntDataFloat(client, v_0) * long_push / 2.0;
finalvec[1] = GetEntDataFloat(client, v_1) * long_push / 2.0;
finalvec[2] = long_push * 50.0;
SetEntDataVector(client, v_b, finalvec, true);
}
}
}
}
« Last Edit: July 31, 2010, 09:10:15 AM by Ownz »

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Headcrab
« Reply #1 on: July 02, 2010, 12:32:07 AM »
Needs 2 more skills,

1. Fangs - Damage over time!
2. Latch On - % when attacker kills headcrab to latch on applying slow dmg until attacker dies and headcrab is reborn

stinkyfax

  • Full Member
  • ***
  • Posts: 120
    • View Profile
    • Email
Re: Headcrab
« Reply #2 on: July 05, 2010, 02:29:08 PM »
Needs 2 more skills,

1. Fangs - Damage over time!
2. Latch On - % when attacker kills headcrab to latch on applying slow dmg until attacker dies and headcrab is reborn
Damn I love 'latch on' idea, though I would make it require you to knife (not kill but just hurt) attacker before he kills you, or any enemy before you are killed.

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Headcrab
« Reply #3 on: July 05, 2010, 10:14:53 PM »
This race has some errors which I fixed since it was coded for an old version but I dont have paw nknowledge yet for weapon restrictions: 

I think this is the part of the code that restricts:
Code: [Select]
public OnClientPutInServer(client)
{
SDKHook(client, SDKHook_WeaponCanUse, OnWeaponCanUse);
}

public Action:OnWeaponCanUse(client, weapon)
{
decl String:name[64];
GetEdictClassname(weapon, name, sizeof(name));

if(StrEqual(name, "weapon_knife", false))
return Plugin_Continue;

return Plugin_Handled;
}

but it is restrictin ALL races to knife only instead of just headcrab,,
should I put a check to see if client is thisRaceID or will that not do it because the commadn is global?

someone please explain this to me

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Headcrab
« Reply #4 on: July 05, 2010, 10:19:28 PM »
if(War3_GetRace(client)== thisraceidvariable){
blah then check knife block
}

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Headcrab
« Reply #5 on: July 06, 2010, 12:09:33 AM »
is the blah knife chceck block Ihave there correct?

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Headcrab
« Reply #6 on: July 06, 2010, 08:51:50 AM »
dont know

Naris

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • Email
Re: Headcrab
« Reply #7 on: July 06, 2010, 12:19:26 PM »
Yes, that should work.

Here is one that should work for all mods, not just CStrike

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Headcrab
« Reply #8 on: July 06, 2010, 02:26:57 PM »
I want to fix the floating knife above models head

in EST we would set invisible alpha to 0 with weapon and then after short delay like 1 second
we woudl set alpha back to max but not the weapon

this way the weapon is still there but invisible

Is there a command to only set invisibility of knife?

or do we do somethign like this?

Code: [Select]
            if(GetClientTeam(client) == 3)
                SetEntityModel(client, "models/headcrab.mdl"),
                War3_SetBuff(client,fInvisibilitySkill,raceID,0.0),
                CreateTimer(1.50,War3_SetBuff(client,fInvisibilitySkill,raceID,1.0));
            else
                SetEntityModel(client, "models/headcrabblack.mdl"),
                War3_SetBuff(client,fInvisibilitySkill,raceID,0.0),
                CreateTimer(1.50,War3_SetBuff(client,fInvisibilitySkill,raceID,1.0));

also how to set have buff not include weapon on third line?

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Headcrab
« Reply #9 on: July 06, 2010, 02:29:18 PM »
you cant use createtimer to directly issue a function call with parameters
you ahve to use a helper function

CreateTimer(1.5,helperfunc);

public Action:helperfunc(Handle:h, any:data){
   War3_SetBuff(client,fInvisibilitySkill,raceID,1.0); //make visible again
}

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Headcrab
« Reply #10 on: July 06, 2010, 02:29:39 PM »
can we do
War3_SetBuff(weapon,fInvisibilitySkill,raceID,0.0)
or
War3_SetBuff(knife,fInvisibilitySkill,raceID,0.0)
or
War3_SetBuff(weapon_knife,fInvisibilitySkill,raceID,0.0)

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Headcrab
« Reply #11 on: July 06, 2010, 02:30:19 PM »
War3_SetBuff can only be clients

you have to track the weapon yourself

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Headcrab
« Reply #12 on: July 06, 2010, 02:30:47 PM »
How to track weapon?

u cant change alpha of entity or weapon or whatever?

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Headcrab
« Reply #13 on: July 06, 2010, 02:31:46 PM »
you can change the alpha of a weapon, its an entity

you have to find the entity of the weapon wiht some function (i dont know which function but there is one)

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Headcrab
« Reply #14 on: July 06, 2010, 02:32:31 PM »
can u name another race or file that does this already so I can look and learn from it instead of googling random and never finding it?

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Headcrab
« Reply #15 on: July 06, 2010, 02:33:26 PM »
try shopitems.sp, and search "weapon_knife"

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Headcrab
« Reply #16 on: July 06, 2010, 02:36:45 PM »
         new ent=GetEntDataEnt2(x,ActiveWeaponOffset);//MyWeaponsOffset);//ActiveWeaponOffset);
         if(ent>0 && IsValidEdict(ent))
         {
            decl String:wepName[64];
            GetEdictClassname(ent,wepName,64);
            if(StrEqual(wepName,"weapon_knife",true))
            {
               War3_SetBuffItem(x,fInvisibilityItem,64,0.0);

??

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Headcrab
« Reply #17 on: July 06, 2010, 02:38:45 PM »
weapon is not a client, you cant use buff, you ahve to manually remember this weapon, and use SetAlpha of some sort

search for setalpha in playertracking

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Headcrab
« Reply #18 on: July 06, 2010, 02:39:36 PM »
SetPlayerAlpha(..) in playertracking.inc

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Headcrab
« Reply #19 on: July 06, 2010, 02:40:41 PM »
public SetWeaponAlpha(client,alpha)
{
   new wep=GetEntDataEnt2(client,m_OffsetActiveWeapon);
   if(wep>MaxClients && IsValidEdict(wep))
   {
      SetPlayerAlpha(wep,alpha);
   }
}

how to use

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Headcrab
« Reply #20 on: July 06, 2010, 02:41:26 PM »
Code: [Select]
public SetWeaponAlpha(client,alpha)
{
   new wep=GetEntDataEnt2(client,m_OffsetActiveWeapon);
   if(wep>MaxClients && IsValidEdict(wep))
   {
      SetPlayerAlpha(wep,0);
   }
}
Do I need to do all this or can I just put setPlayerAlpha(wep,0) in race file?

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Headcrab
« Reply #21 on: July 06, 2010, 02:41:53 PM »
you have to copy the code from SetPlayerAlpha, not use SetPlayerAlpha

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Headcrab
« Reply #22 on: July 06, 2010, 02:42:46 PM »
there already is a code for setweaponalpha why use setplayeralpha?

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Headcrab
« Reply #23 on: July 06, 2010, 02:47:56 PM »
you cant reach that code cuz its in war3source.smx so you have to implement it yourself in your race

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Headcrab
« Reply #24 on: July 06, 2010, 02:50:22 PM »
yea how , can u show me what to put for the sake of learning, I dont know how to implement myself yet