Raised This Month: $ Target: $400
 0% 

Help with Ents, script not working


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Fredd
Veteran Member
Join Date: Jul 2007
Old 10-15-2007 , 01:46   Help with Ents, script not working
Reply With Quote #1

ok i have not got a single error i tested it with bots but it doesn't work, but i think im doing im something wrong some where so someone could help me out would be great.
gameconfig file:
Code:
"Games"
{
	"cstrike"
	{
		"Offsets"
		{
			"SetModel"
			{
				"windows"	"25"
				"linux"		"26"
			}
		}
	}
}
and here is the plugin
Code:
#include <sourcemod> #include <sdktools> #define MAX_AMMO 64   new g_WeapActiveOffset = 1896; new g_ClipOffset = 1208; new g_EntOrigin = 796; new MaxClients = 0; new AmmoCount = 0; new Handle:_GameConf; new Handle:_SetModel;   new Handle:AmmoThinkTimer[2085] public Plugin:myinfo = {     name = "",     author = "Fredd",     description = "",     version = "0.1",     url = "www.sourcemod.net" } public OnMapStart() {       MaxClients = GetMaxClients()     PrecacheModel("models/items/357ammo.mdl") } public OnPluginStart() {       g_WeapActiveOffset  = FindSendPropOffs("CAI_BaseNPC", "m_hActiveWeapon");     g_ClipOffset        = FindSendPropOffs("CBaseCombatWeapon", "m_iClip2");     g_EntOrigin     = FindSendPropOffs("CBaseEntity", "m_vecOrigin");     _GameConf = LoadGameConfigFile("plugin.droppedammo");       StartPrepSDKCall(SDKCall_Entity);     PrepSDKCall_SetFromConf(_GameConf, SDKConf_Virtual, "SetModel");     PrepSDKCall_AddParameter(SDKType_String, SDKPass_Plain);     _SetModel = EndPrepSDKCall();         HookEvent("player_death", PlayerDeath) } public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast) {     if(AmmoCount == MAX_AMMO)         return Plugin_Continue         new client      = GetClientOfUserId(GetEventInt(event, "userid"))     new iActiveWeap     = GetEntDataEnt(client, g_WeapActiveOffset)     new WeapClip2       = GetEntData(iActiveWeap, g_ClipOffset)     //new WeapAmmoType  = GetEntProp(iActiveWeap, Prop_Send, "m_iPrimaryAmmoType")         if(WeapClip2 == 0)         return Plugin_Continue         new AmmoEnt = CreateEntityByName("ammo_entity")         if(AmmoEnt)     {         AmmoCount++         new Float:vec[3];         GetClientAbsOrigin(client, vec);         DispatchSpawn(AmmoEnt);         TeleportEntity(AmmoEnt, vec, NULL_VECTOR, NULL_VECTOR);         SDKCall(_SetModel, AmmoEnt, "models/items/357ammo.mdl");                 AmmoThinkTimer[AmmoEnt] = CreateTimer(0.50, EntThink, AmmoEnt, TIMER_REPEAT);     }     return Plugin_Continue; } public Action:EntThink(Handle:timer, any:Ent)   {     for(new i = 1; i <= MaxClients; i++)     {         if(IsClientInGame(i))         {             new Float:AmmoOrigin[3], Float:ClientOrigin[3];                         GetEntDataVector(Ent, g_EntOrigin, AmmoOrigin)             GetClientAbsOrigin(i, ClientOrigin)                         if(GetVectorDistance(AmmoOrigin, ClientOrigin) < 10 )             {                 new iActiveWeap     = GetEntDataEnt(i, g_WeapActiveOffset)                 new WeapClip2       = GetEntData(iActiveWeap, g_ClipOffset)                 //new WeapAmmoType  = GetEntProp(iActiveWeap, Prop_Send, "m_iPrimaryAmmoType")                                 if(WeapClip2 >= 90)                     return Plugin_Continue                                 SetEntData(iActiveWeap, WeapClip2, 90, 4, true);                                 RemoveEdict(Ent)                 AmmoCount--                 AmmoThinkTimer[Ent] = INVALID_HANDLE                 KillTimer(AmmoThinkTimer[Ent])             }         }             }     return Plugin_Continue; }
__________________
Need a private coder? AMXX, SourceMOD, MMS? PM me!

Last edited by Fredd; 10-15-2007 at 20:39.
Fredd is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 10-15-2007 , 06:48   Re: Help with Ents, script not working
Reply With Quote #2

The main reason you cant pick up the clips is that you do GetMaxClients() in OnPluginStart() while it will return 0. The correct forward to call it in is OnMapStart().

Also, AmmoThinkTimer uses AmmoEnt as its index, which is most certainly not guaranteed to be of value between 0 and 63 (referring to MAX_AMMO).

In EntThink() you start the loop from entity index 0 which is world, you might wanna change it to something like this:
Code:
for(new i = 1; i <= MaxClients; i++)
It would also be preferable if you checked if the client is actually valid with IsClientInGame().

Lastly, you never remove the timers after picking up the ammo, only assign their handles to INVALID_HANDLE.

__________________
plop
p3tsin is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 10-15-2007 , 06:54   Re: Help with Ents, script not working
Reply With Quote #3

Found the SetModel offset!

025 CBaseFlex::SetModel(char const*)

http://plugins.mfzb.de/offsets/CSTRIKE_CCSPlayer.txt
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
Fredd
Veteran Member
Join Date: Jul 2007
Old 10-15-2007 , 20:01   Re: Help with Ents, script not working
Reply With Quote #4

Nican: i like using sigs better lol
what kinda of array i could use to store entity timers in? [4097] ? max ents + 1. or just GetMaxEntitie() + 1....
edit: it's 2084
__________________
Need a private coder? AMXX, SourceMOD, MMS? PM me!

Last edited by Fredd; 10-15-2007 at 20:10.
Fredd is offline
Fredd
Veteran Member
Join Date: Jul 2007
Old 10-15-2007 , 20:38   Re: Help with Ents, script not working
Reply With Quote #5

ok i tried doing what you guys suggested, but still the script doesn't work, and no errors. look at first post for updated version
__________________
Need a private coder? AMXX, SourceMOD, MMS? PM me!
Fredd is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 10-19-2007 , 16:48   Re: Help with Ents, script not working
Reply With Quote #6

The player model is 62 units high when standing and 45 units when ducking. GetClientAbsOrigin() gets the origin from the center of the model which means that the distance to the ground even when ducking would be 22.5 units which is greater than 10.

You need to decrease the height from ClientOrigin z-axis to get it on the same level, or just increase the max distance.

Code:
decl Float:maxs[3]
GetClientMaxs(i, maxs)
ClientOrigin[2] -= maxs[2]

if(GetVectorDistance(AmmoOrigin, ClientOrigin) < 10 )
{
	//...
}
The timers are still not being removed.. this time you first invalidate the handle and then try to remove it

Code:
CloseHandle(AmmoThinkTimer[Ent])
You wont even need to set the value of AmmoThinkTimer[Ent] to INVALID_HANDLE as you never check if the handle is valid.
__________________
plop
p3tsin is offline
Fredd
Veteran Member
Join Date: Jul 2007
Old 10-19-2007 , 18:28   Re: Help with Ents, script not working
Reply With Quote #7

ok ill try that, but the model doesn't seem to be showing on the ground either way
__________________
Need a private coder? AMXX, SourceMOD, MMS? PM me!
Fredd is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 10-19-2007 , 20:18   Re: Help with Ents, script not working
Reply With Quote #8

Why didn't you say so? All the time I assumed you had problems picking up the ammo...

Anyways, you sure CAI_BaseNPC::m_hActiveWeapon will return a valid weapon index in player_death post? If not, you could try making it a pre hook instead.

Oh and by the way, CreateEntityByName() returns -1 on failure, not 0.
__________________
plop
p3tsin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode