PDA

View Full Version : vexd_pfntouch & Weapons on ground...


ThantiK
05-26-2004, 05:00
Does vexd_pfntouch get if a player is touching a weapon on the ground?

I'm going to be making a plugin that isn't a full csdm, but just allows multiple weapons to be picked up, etc.

Would someone show me an example of how to display perhaps on hud, if a weapon on the ground was touched?

BAILOPAN
05-26-2004, 05:12
yes, pfn_touch() will do this:


public pfn_touch(ptr, ptd)
{
if ((ptr>=1 && ptr<=32) && is_user_connected(ptr)) {
/* Do stuff here, ptr is weapon handle */
}

return PLUGIN_CONTINUE
}

ThantiK
05-26-2004, 06:10
Thanks bailo. I will probably be using a lot of the CSDM code to look at, but not directly copy and pasting any of it. I noticed the pfn touch but once you start getting into PAGES of code, unless your the original author, it takes a while to get everything down-pat.

Haven't seen you online AIM lately. Got a new SN: TKWiredcom

Thanks for the info. Now I gotta install amxx 0.16 again on my rented/test server ;)

QwertyAccess
05-26-2004, 21:28
BAILOPAN has hidden himself from IRC and AIM, no way to contact him cept on the forums as far as i know. http://www.nsarmslab.com/qwerty/smileys/tongue.gif

Girthesniper
05-26-2004, 21:29
yea, balio has hidden him self in his shell :)

BAILOPAN
05-26-2004, 22:22
Feel free to use all the code from CSDM as you want (it's GPL'd)

I'm on IRC often ;] but I am busy nowadays

QwertyAccess
05-26-2004, 22:24
like your sig says Legimate Bussiness! http://www.nsarmslab.com/qwerty/smileys/tongue.gif, I miss being able to talk to you on AIM though i cant bother you anymore!

ThantiK
05-27-2004, 00:56
is vexd_pfntouch ran when you touch another entity?...

How do dis work?...lol

Sorry, I haven't messed with amx for a while.

BAILOPAN
05-27-2004, 00:58
pfn_touch(ptd, ptr) is run whenever an entity touches another entity. When a player touches something, their id will be the second argument, the entity handle being the first

ThantiK
05-27-2004, 01:06
Ok, I got it workin...what format is ptr and ptd in, and how can I tell which weapon a player touched?

Location: back of turtle =)...love it.

ThantiK
05-27-2004, 01:09
nvm, I'm starting to get it now, its coming back to me...

although Yea, I'm looking directly @ csdm

ThantiK
05-27-2004, 01:25
ok, I'm back to needing help.

How can I find out if the player touches a weapon and what weapon it is?...and how to put it in his inventory.

Its getting confusing now. I miss SmallEd.

BAILOPAN
05-27-2004, 01:40
Rewrite this function so it compares against weapon models instead of weapon names:


//Change this to getWpFromModel(wp[])
getCSDMWpId(wp[])
{
if (equali(wp, "csdmw_p228")) {
return CSW_P228
} else if (equali(wp, "csdmw_scout")) {
return CSW_SCOUT
} else if (equali(wp, "csdmw_hegrenade")) {
return CSW_HEGRENADE
} else if (equali(wp, "csdmw_xm1014")) {
return CSW_XM1014
} else if (equali(wp, "csdmw_c4")) {
return CSW_C4
} else if (equali(wp, "csdmw_mac10")) {
return CSW_MAC10
} else if (equali(wp, "csdmw_aug")) {
return CSW_AUG
} else if (equali(wp, "csdmw_smokegrenade")) {
return CSW_SMOKEGRENADE
} else if (equali(wp, "csdmw_elite")) {
return CSW_ELITE
} else if (equali(wp, "csdmw_fiveseven")) {
return CSW_FIVESEVEN
} else if (equali(wp, "csdmw_ump45")) {
return CSW_UMP45
} else if (equali(wp, "csdmw_sg550")) {
return CSW_SG550
} else if (equali(wp, "csdmw_galil")) {
return CSW_GALIL
} else if (equali(wp, "csdmw_famas")) {
return CSW_FAMAS
} else if (equali(wp, "csdmw_usp")) {
return CSW_USP
} else if (equali(wp, "csdmw_glock18")) {
return CSW_GLOCK18
} else if (equali(wp, "csdmw_awp")) {
return CSW_AWP
} else if (equali(wp, "csdmw_mp5navy")) {
return CSW_MP5NAVY
} else if (equali(wp, "csdmw_m249")) {
return CSW_M249
} else if (equali(wp, "csdmw_m3")) {
return CSW_M3
} else if (equali(wp, "csdmw_m4a1")) {
return CSW_M4A1
} else if (equali(wp, "csdmw_tmp")) {
return CSW_TMP
} else if (equali(wp, "csdmw_g3sg1")) {
return CSW_G3SG1
} else if (equali(wp, "csdmw_flashbang")) {
return CSW_FLASHBANG
} else if (equali(wp, "csdmw_deagle")) {
return CSW_DEAGLE
} else if (equali(wp, "csdmw_sg552")) {
return CSW_SG552
} else if (equali(wp, "csdmw_ak47")) {
return CSW_AK47
} else if (equali(wp, "csdmw_knife")) {
return CSW_KNIFE
} else if (equali(wp, "csdmw_p90")) {
return CSW_P90
}

return 0
}


Then do this:

public pfn_touch(ptr, ptd)
{
if ((ptd>=1 && ptd<=32) && is_user_connected(ptd)) {
new Model[32], wp, wpname[32]
entity_get_string(ptr, EV_SZ_model, Model, 31)
wp = getWpFromModel(Model)
get_weaponname(wp, wpname, 31)
give_item(ptd, wpname)
}

return PLUGIN_CONTINUE
}


sorry I mixed up ptd and ptr in my original post

ThantiK
05-27-2004, 02:15
Thanks bail.

Damn, lol, I wasn't really wanting ALL of that, but thanks!

I'll be posting other help topics soon...

Peli
05-27-2004, 02:16
Very nice Bail. :)

ThantiK
05-27-2004, 02:32
Wow, nice -- I could use this for putting a chicken model on the map and if you touch it you do something. Glow, llama, etc...lol

Thats sweet, thanks bailo

ThantiK
05-27-2004, 02:50
I got a problem

I have AK, and Colt

I drop AK -- I switch to colt and it gives me AK back?

I can drop ak's and colts crazy around the map and it just keeps giving them to me even if I'm not on one...any way to delay this so I can drop it from inventory without picking it up again while in the air?

Also, is there a function to get a certain number of chars on the left of a string?...I know in VB its left(num, string) (Its so I can remove the entity once picked up...I gotta check if its a weapon_)

PM
05-27-2004, 05:41
not sure about the first problem, but the second one:


new string[64];
// some native that fills string with data
string[5] = 0;
// string now contains only the first 5 characters returned by the native.


It works because strings in Small are (like strings in C) zero-terminated arrays of characters. So when you write a 0 to the index x, the string will only appear to have x characters (not x-1 because 0 is a valid index).

Note that you can't do this on constant strings ( "balbla"[4] = 0 :D ) and when you do this on a string, you modify it (VB's Left makes a new string, so the original string stays unchanged).

ThantiK
05-27-2004, 07:33
Thanks PM...so I should end up with something like....

model[32] is "weapon_g3sg1"
model[6] = 0

model will then be "weapon_" after I do model[6] = 0?

Of course I'd be moving it to a new var to check it.

PM
05-27-2004, 09:46
no, model will be "weapon" then. (6 chars)

DopeFish
05-27-2004, 10:22
I had a similar problem with my plugin (custom items that can be dropped and picked up). I simply made a bool:canpickup[33] that I set to false for the player when someone drops something. It is set back to true 0.3 seconds later (item is dropped with a 400 velocity in the direction the player is aiming, you may need to alter the timing if the weapon is dropped faster or slower).
The top of public pfn_touch(ptr, ptd) looks like this for my plugin:

public pfn_touch(ptr, ptd) {
new itemClassName[MAX_NAME_LENGTH], playerClassname[MAX_NAME_LENGTH]
entity_get_string(ptr, EV_SZ_classname, itemClassName, MAX_NAME_LENGTH-1);
entity_get_string(ptd, EV_SZ_classname, playerClassname, MAX_NAME_LENGTH-1)
if(equal(itemClassName,"wc3item") && equal(playerClassname,"player")) {
if(!canpickup[ptd])
return PLUGIN_CONTINUE
.
.
.


viola, no more premature picking up stuff.

ThantiK
05-28-2004, 04:59
DopeFish, how do I set that per-player?...how do I find when the user drops and item to be able to block it?

Another question...is there a way to get entity data to get ACTUALLY what is on the ground? -- say, a colt on ground has silencer on it, and 13 bullets, and 40 in the spare clips?...I want to give the player THAT weapon...and if they run out they can drop the empty item?

DopeFish
05-28-2004, 05:27
in my case it was easy since they had to use a menu command or a bind to drop the item, you may need to hook the drop command. this code snippet may help you further:



#define MAX_NAME_LENGTH 32
new bool:canpickup[33]

public plugin_init() {
register_clcmd("drop","cmd_drop")
register_event("ResetHUD", "new_round", "b")
}

public cmd_drop(id)
{
canpickup[id] = false
new ident[1]
ident[0] = id
set_task(0.3,"safedrop",2300+id,ident,1)
return PLUGIN_CONTINUE
}

public safedrop(ident[]) {
canpickup[ident[0]] = true
return PLUGIN_HANDLED
}


public new_round(id){
canpickup[id] = true
}

public pfn_touch(ptr, ptd) {
new itemClassName[MAX_NAME_LENGTH], playerClassname[MAX_NAME_LENGTH]
entity_get_string(ptr, EV_SZ_classname, itemClassName, MAX_NAME_LENGTH-1);
entity_get_string(ptd, EV_SZ_classname, playerClassname, MAX_NAME_LENGTH-1)
itemClassName[6]=0
if(equal(itemClassName,"weapon") && equal(playerClassname,"player")) {
if(!canpickup[ptd])
return PLUGIN_CONTINUE
// player is touching weapon and it is not the one he just dropped
// add code here ;) (like setting the itemClassName back to the full name)
entity_get_string(ptr, EV_SZ_classname, itemClassName, MAX_NAME_LENGTH-1);
}
return PLUGIN_CONTINUE
}


I wrote it off the top of my head and copied some stuff from my plugins so some things may be needless, but I think you'll get the generel idea how it works. hope this helps.

The second part of the question is a little harder for me since I've never coded that kind of stuff, "Jhonny got his gun" would definatly know an answer to that question.

ThantiK
05-28-2004, 05:47
wow, thanks.

Forgot about the register_clcmd function...(doh!)

I used to work/learn amx 24/7 but I've been working on websites, etc and AMXX .16 was unstable for me so I went back to old stuff...and I'm starting again working on amxx plugins anticipating the .20 release.

ThantiK
05-28-2004, 06:10
btw, thanks guys...

heres my code so far.

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fun>
#define MAX_NAME_LENGTH 32
new bool:canpickup[33]

public plugin_init()
{
register_plugin("MultiWeapons","0.1","ThantiK")
register_clcmd("drop","cant_drop")

return PLUGIN_CONTINUE
}

public cant_drop(id)
{
canpickup[id] = false
new ident[1]
ident[0] = id
set_task(0.3,"can_drop",2300+id,ident,1)
return PLUGIN_CONTINUE
}

public can_drop(ident[]) {
canpickup[ident[0]] = true
return PLUGIN_HANDLED
}

public pfn_touch(ptr, ptd)
{
if ((ptd>=1 && ptd<=32) && is_user_connected(ptd)) {
//can I just do another "&& canpickup[ptd]" to get rid of that if function?

new Model[32], wp, wpname[32]

if(!canpickup[ptd]) {
return PLUGIN_CONTINUE
}

entity_get_string(ptr, EV_SZ_model, Model, 31)
wp = getWpFromModel(Model)
get_weaponname(wp, wpname, 31)
give_item(ptd, wpname)
}

return PLUGIN_CONTINUE
}

getWpFromModel(wp[])
{
if (equali(wp, "models/w_p228")) {
return CSW_P228
} else if (equali(wp, "models/w_scout.mdl")) {
return CSW_SCOUT
} else if (equali(wp, "models/w_hegrenade.mdl")) {
return CSW_HEGRENADE
} else if (equali(wp, "models/w_xm1014.mdl")) {
return CSW_XM1014
} else if (equali(wp, "models/w_c4.mdl")) {
return CSW_C4
} else if (equali(wp, "models/w_mac10.mdl")) {
return CSW_MAC10
} else if (equali(wp, "models/w_aug.mdl")) {
return CSW_AUG
} else if (equali(wp, "models/w_smokegrenade.mdl")) {
return CSW_SMOKEGRENADE
} else if (equali(wp, "models/w_elite.mdl")) {
return CSW_ELITE
} else if (equali(wp, "models/w_fiveseven.mdl")) {
return CSW_FIVESEVEN
} else if (equali(wp, "models/w_ump45.mdl")) {
return CSW_UMP45
} else if (equali(wp, "models/w_sg550.mdl")) {
return CSW_SG550
} else if (equali(wp, "models/w_galil.mdl")) {
return CSW_GALIL
} else if (equali(wp, "models/w_famas.mdl")) {
return CSW_FAMAS
} else if (equali(wp, "models/w_usp.mdl")) {
return CSW_USP
} else if (equali(wp, "models/w_glock18.mdl")) {
return CSW_GLOCK18
} else if (equali(wp, "models/w_awp.mdl")) {
return CSW_AWP
} else if (equali(wp, "models/w_mp5navy.mdl")) {
return CSW_MP5NAVY
} else if (equali(wp, "models/w_m249.mdl")) {
return CSW_M249
} else if (equali(wp, "models/w_m3.mdl")) {
return CSW_M3
} else if (equali(wp, "models/w_m4a1.mdl")) {
return CSW_M4A1
} else if (equali(wp, "models/w_tmp.mdl")) {
return CSW_TMP
} else if (equali(wp, "models/w_g3sg1.mdl")) {
return CSW_G3SG1
} else if (equali(wp, "models/w_flashbang.mdl")) {
return CSW_FLASHBANG
} else if (equali(wp, "models/w_deagle.mdl")) {
return CSW_DEAGLE
} else if (equali(wp, "models/w_sg552.mdl")) {
return CSW_SG552
} else if (equali(wp, "models/w_ak47.mdl")) {
return CSW_AK47
} else if (equali(wp, "models/w_knife.mdl")) {
return CSW_KNIFE
} else if (equali(wp, "models/w_p90.mdl")) {
return CSW_P90
}

return 0
}

My only problems now are getting rid of the entity that just got picked up, and making sure the gun has the same ammo it got dropped with...and making a menu frontend to make sure they can buy multiple weapons and also pick them up.

Maybe I should make a cvar for multi_canpickup, multi_canbuy?

ts2do
05-29-2004, 18:23
nooooo u dont get rid of the entity...u just make it invisible and movetype_follow and aiment as the player

ThantiK
05-29-2004, 18:35
wtf, you just lost me...

BAILOPAN
05-29-2004, 18:58
you have to remove the weapon off the ground once you give it to the player.

there is code in CSDM to show you how to do this: look in safe_rment and replaceWeapon (just strip out the code that creates a fake weapon to replace it)