Raised This Month: $ Target: $400
 0% 

[Solved] Integer parameter passed to stock function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Boonie
Member
Join Date: Aug 2015
Old 08-16-2015 , 10:57   [Solved] Integer parameter passed to stock function
Reply With Quote #1

I am trying to get an integer (1 or 0) from a function, and use it in another, but I cannot get it to work. I'm not sure if I have the syntax correct or not. I tried using int: {1} but that didnt work, I also tried view_as<int>(1) and that didn't work either. Any ideas?
PHP Code:
public Action:Hook_Start(Handle:event, const String:name[], bool:dontBroadcast) {
    
CreateZone(Float: { 1732.0, -2812.0, -31.0 }, Float: { -30.0, -50.0, -100.0 }, Float: { 30.050.0100.0 }, { } );
}

stock CreateZone(Float:position[3], Float:minbounds[3], Float:maxbounds[3], numbers[]) {
    
// snip //
    
DispatchKeyValue(entbuild"AllowSentry"numbers);
    
// snip //


Last edited by Boonie; 08-17-2015 at 07:32.
Boonie is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 08-16-2015 , 11:41   Re: Integer parameter passed to stock function
Reply With Quote #2

Your passing an int array to a method expecting a string value.
__________________
WildCard65 is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 08-16-2015 , 12:01   Re: Integer parameter passed to stock function
Reply With Quote #3

PHP Code:
public Action:Hook_Start(Handle:event, const String:name[], bool:dontBroadcast) {
    
CreateZone(Float: { 1732.0, -2812.0, -31.0 }, Float: { -30.0, -50.0, -100.0 }, Float: { 30.050.0100.0 }, 1);
}

stock CreateZone(Float:position[3], Float:minbounds[3], Float:maxbounds[3], numbers) {
    
// snip //
    
DispatchKeyValue(entbuild"AllowSentry"numbers);
    
// snip //


Last edited by Miu; 08-16-2015 at 12:07.
Miu is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 08-16-2015 , 15:34   Re: Integer parameter passed to stock function
Reply With Quote #4

You still need to convert it to a string to pass to DispatchKeyValue as it expects:
first param: ent index(typed int)
2nd: string for keyvalue name
3rd: string for value
__________________
WildCard65 is offline
Boonie
Member
Join Date: Aug 2015
Old 08-16-2015 , 23:17   Re: Integer parameter passed to stock function
Reply With Quote #5

Quote:
Originally Posted by WildCard65 View Post
You still need to convert it to a string to pass to DispatchKeyValue as it expects:
first param: ent index(typed int)
2nd: string for keyvalue name
3rd: string for value

Im not quite sure how I would convert the int to a string, would it be something like this?

PHP Code:
public Action:Hook_Start(Handle:event, const String:name[], bool:dontBroadcast) {
    
CreateZone(Float: { 1732.0, -2812.0, -31.0 }, Float: { -30.0, -50.0, -100.0 }, Float: { 30.050.0100.0 }, 1);
}

stock CreateZone(Float:position[3], Float:minbounds[3], Float:maxbounds[3], numbers) {
    
// snip //
    
new String:bsent[1] = numbers;
    
DispatchKeyValue(entbuild"AllowSentry"bsent);
    
// snip //

I know I can get it working with using a string, like below, but I would like to use 1 & 0 instead of Dec.


PHP Code:
public Action:Hook_Start(Handle:event, const String:name[], bool:dontBroadcast) {
    
CreateZone(Float: { 1732.0, -2812.0, -31.0 }, Float: { -30.0, -50.0, -100.0 }, Float: { 30.050.0100.0 }, String: { 49 });
}

stock CreateZone(Float:position[3], Float:minbounds[3], Float:maxbounds[3], String:numbers[2]) {
    
// snip //
    
DispatchKeyValue(entbuild"AllowSentry"numbers);
    
// snip //

umbers);

Last edited by Boonie; 08-16-2015 at 23:20.
Boonie is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 08-17-2015 , 05:02   Re: Integer parameter passed to stock function
Reply With Quote #6

new String:n[8];
IntToString(numbers, n, sizeof(n));
Miu is offline
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 08-17-2015 , 06:08   Re: Integer parameter passed to stock function
Reply With Quote #7

If it's a new plugin I recommand you to use the new syntax.
__________________
Benoist3012 is offline
Boonie
Member
Join Date: Aug 2015
Old 08-17-2015 , 07:24   Re: Integer parameter passed to stock function
Reply With Quote #8

Quote:
Originally Posted by Miu View Post
new String:n[8];
IntToString(numbers, n, sizeof(n));
I didn't know there was an IntToString, but I am learning. Anyways, this worked great, thanks.

Quote:
Originally Posted by Benoist3012 View Post
If it's a new plugin I recommand you to use the new syntax.
This is a new plugin, and I made sure it was in the new syntax.

Last edited by Boonie; 08-17-2015 at 07:31.
Boonie is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 08-17-2015 , 10:40   Re: Integer parameter passed to stock function
Reply With Quote #9

Quote:
Originally Posted by Boonie View Post
I didn't know there was an IntToString, but I am learning. Anyways, this worked great, thanks.
Always search the API (https://sm.alliedmods.net/new-api/) to see if there's a function that can do what you want.

Quote:
Originally Posted by Benoist3012 View Post
If it's a new plugin I recommand you to use the new syntax.
Quote:
Originally Posted by Boonie View Post
This is a new plugin, and I made sure it was in the new syntax.
It's not in the new syntax. You're using old syntax code. To enforce new syntax, add:

PHP Code:
#pragma semicolon 1 // you should have this anyway
#pragma newdecls required 
BELOW your #include file statements, and then it will complain if you use old syntax.

https://wiki.alliedmods.net/Introduc...SourcePawn_1.7

Last edited by Potato Uno; 08-17-2015 at 10:40.
Potato Uno is offline
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 08-17-2015 , 12:21   Re: [Solved] Integer parameter passed to stock function
Reply With Quote #10

PHP Code:
stock void CreateZone(float position[3], float minbounds[3], float maxbounds[3], int number)
{
    
// snip //
    
DispatchKeyValue(entbuild"AllowSentry"numbers);
    
// snip //

Example of what your stock must look like in new syntax

Edit: And because I love sourcepawn I did you other stock too

PHP Code:
public Action Hook_Start(handle event, const char[] namebool dontBroadcast)
{
    
CreateZone(float 1732.0, -2812.0, -31.0 }, float { -30.0, -50.0, -100.0 }, float 30.050.0100.0 },int 1);//idk if int is need

__________________

Last edited by Benoist3012; 08-17-2015 at 12:30.
Benoist3012 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 14:55.


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